diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2023-11-01 01:31:49 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2023-11-01 01:37:32 +0300 |
commit | 54999533a393665a28e42d526e9da215d024c873 (patch) | |
tree | 1af99024207abe8de23d2e6d95d52733345be527 /internal | |
parent | be0275d5948670f17bacca9beffe01bf02d4e6d5 (diff) |
Set generic type for cache upgrade
Diffstat (limited to 'internal')
-rw-r--r-- | internal/lru/lru.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/internal/lru/lru.go b/internal/lru/lru.go index b53803c9..1069bd7f 100644 --- a/internal/lru/lru.go +++ b/internal/lru/lru.go @@ -30,7 +30,7 @@ type Cache struct { op string duration time.Duration maxSize int64 - cache *ccache.Cache + cache *ccache.Cache[any] metricCachedEntries *prometheus.GaugeVec metricCacheRequests *prometheus.CounterVec } @@ -47,11 +47,11 @@ func New(op string, opts ...Option) *Cache { opt(c) } - configuration := ccache.Configure() + configuration := ccache.Configure[any]() configuration.MaxSize(c.maxSize) configuration.ItemsToPrune(uint32(c.maxSize) / itemsToPruneDiv) configuration.GetsPerPromote(getsPerPromote) // if item gets requested frequently promote it - configuration.OnDelete(func(*ccache.Item) { + configuration.OnDelete(func(*ccache.Item[any]) { if c.metricCachedEntries != nil { c.metricCachedEntries.WithLabelValues(op).Dec() } @@ -64,7 +64,7 @@ func New(op string, opts ...Option) *Cache { // FindOrFetch will try to get the item from the cache if exists and is not expired. // If it can't find it, it will call fetchFn to retrieve the item and cache it. -func (c *Cache) FindOrFetch(cacheNamespace, key string, fetchFn func() (interface{}, error)) (interface{}, error) { +func (c *Cache) FindOrFetch(cacheNamespace, key string, fetchFn func() (any, error)) (any, error) { item := c.cache.Get(cacheNamespace + key) if item != nil && !item.Expired() { |