MCPcopy Create free account
hub / github.com/flyteorg/flyte / NewAutoRefreshCache

Function NewAutoRefreshCache

flytestdlib/utils/auto_refresh_cache.go:63–86  ·  view source on GitHub ↗

Deprecated: This utility is deprecated, it has been refactored and moved into `cache` package.

(syncCb CacheSyncItem, syncRateLimiter RateLimiter, resyncPeriod time.Duration,
	size int, scope promutils.Scope)

Source from the content-addressed store, hash-verified

61
62// Deprecated: This utility is deprecated, it has been refactored and moved into `cache` package.
63func NewAutoRefreshCache(syncCb CacheSyncItem, syncRateLimiter RateLimiter, resyncPeriod time.Duration,
64 size int, scope promutils.Scope) (AutoRefreshCache, error) {
65
66 // If a scope is specified, we'll add a function to log a metric when an object gets evicted
67 var evictionFunction func(key interface{}, value interface{})
68 if scope != nil {
69 counter := scope.MustNewCounter("lru_evictions", "Counter for evictions from LRU")
70 evictionFunction = getEvictionFunction(counter)
71 }
72 lruCache, err := lru.NewWithEvict(size, evictionFunction)
73 if err != nil {
74 return nil, err
75 }
76
77 cache := &autoRefreshCache{
78 syncCb: syncCb,
79 lruMap: lruCache,
80 syncRateLimiter: syncRateLimiter,
81 resyncPeriod: resyncPeriod,
82 scope: scope,
83 }
84
85 return cache, nil
86}
87
88// Thread-safe general purpose auto-refresh cache that watches for updates asynchronously for the keys after they are added to
89// the cache. An item can be inserted only once.

Callers 2

TestCacheTwoFunction · 0.70

Calls 2

getEvictionFunctionFunction · 0.70
MustNewCounterMethod · 0.65

Tested by 2

TestCacheTwoFunction · 0.56