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")
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()

View File

@ -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()