mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
int64 -> time.Duration (#1287)
This commit is contained in:
parent
89ba602e17
commit
bc71989e2c
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user