diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index cbc0a365..fcf38778 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -109,12 +109,12 @@ func (w *workersKV) Init(opts ...store.Option) error { } ttl := w.options.Context.Value("STORE_CACHE_TTL") if ttl != nil { - ttlint64, ok := ttl.(int64) + ttlduration, ok := ttl.(time.Duration) if !ok { log.Fatal("STORE_CACHE_TTL from context must be type int64") } w.cache = ttlcache.NewCache() - w.cache.SetTTL(time.Duration(ttlint64)) + w.cache.SetTTL(ttlduration) w.cache.SkipTtlExtensionOnHit(true) } return nil @@ -279,6 +279,9 @@ func (w *workersKV) Write(r *store.Record) 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) defer cancel() diff --git a/store/cloudflare/options.go b/store/cloudflare/options.go index 71331d12..dd2aee36 100644 --- a/store/cloudflare/options.go +++ b/store/cloudflare/options.go @@ -2,6 +2,7 @@ package cloudflare import ( "context" + "time" "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 -func CacheTTL(ttl int64) store.Option { +func CacheTTL(ttl time.Duration) store.Option { return func(o *store.Options) { if o.Context == nil { o.Context = context.Background()