int64 -> time.Duration (#1287)

This commit is contained in:
Jake Sanders 2020-03-03 13:15:26 +00:00 committed by GitHub
parent 89ba602e17
commit bc71989e2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -109,12 +109,12 @@ func (w *workersKV) Init(opts ...store.Option) error {
} }
ttl := w.options.Context.Value("STORE_CACHE_TTL") ttl := w.options.Context.Value("STORE_CACHE_TTL")
if ttl != nil { if ttl != nil {
ttlint64, ok := ttl.(int64) ttlduration, ok := ttl.(time.Duration)
if !ok { if !ok {
log.Fatal("STORE_CACHE_TTL from context must be type int64") log.Fatal("STORE_CACHE_TTL from context must be type int64")
} }
w.cache = ttlcache.NewCache() w.cache = ttlcache.NewCache()
w.cache.SetTTL(time.Duration(ttlint64)) w.cache.SetTTL(ttlduration)
w.cache.SkipTtlExtensionOnHit(true) w.cache.SkipTtlExtensionOnHit(true)
} }
return nil return nil
@ -279,6 +279,9 @@ func (w *workersKV) Write(r *store.Record) error {
} }
func (w *workersKV) Delete(key string) error { func (w *workersKV) Delete(key string) error {
if w.cache != nil {
w.cache.Remove(key)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()

View File

@ -2,6 +2,7 @@ package cloudflare
import ( import (
"context" "context"
"time"
"github.com/micro/go-micro/v2/store" "github.com/micro/go-micro/v2/store"
) )
@ -53,7 +54,7 @@ func Namespace(ns string) store.Option {
} }
// CacheTTL sets the timeout in nanoseconds of the read/write cache // CacheTTL sets the timeout in nanoseconds of the read/write cache
func CacheTTL(ttl int64) store.Option { func CacheTTL(ttl time.Duration) store.Option {
return func(o *store.Options) { return func(o *store.Options) {
if o.Context == nil { if o.Context == nil {
o.Context = context.Background() o.Context = context.Background()