Cannot use go-cache as backend cache for cache.NewMetric #236
Description
Hi, I was trying to use go-cache
as a backend cache for a cache with prometheus metrics. I expose the prometheus metrics via http localhost:8080/metrics
but this endpoint returns empty response, i.e. no metrics.
Steps for Reproduction
ctx := context.Background()
// initialize backend go-cache store
gocacheClient := gocache.New(5*time.Minute, 10*time.Minute)
gocacheStore := gocache_store.NewGoCache(gocacheClient)
// initialize prometheus metrics store
registry := prometheus.NewRegistry()
promMetrics := metrics.NewPrometheus("my-test-app", metrics.WithRegisterer(registry))
// initialize cache with metrics
cacheManager := cache.NewMetric[any](promMetrics, gocacheStore)
err := cacheManager.Set(ctx, "my-key", []byte("my-value"))
value, err := cacheManager.Get(ctx, "my-key")
fmt.Printf("%s", value)
After inspecting the code I found that gocacheStore
doesn't implement the SetterCacheInterface
interface, which causes switch...case...
miss defined in the function below
Lines 63 to 73 in 96fc2f7
Expected behavior: metrics should be updated and collected by the prometheus registry
Actual behavior: no metrics collected
Platforms:
Go: 1.20
Linux: 3.10.0-1160.105.1.el7.x86_64
Versions:
github.com/eko/gocache/lib/v4 v4.1.5
github.com/eko/gocache/store/go_cache/v4 v4.2.1
If fixing this issue will be on the roadmap, I can help contribute. Thanks!