diff --git a/src/mapper/pkg/metrics_collection_traffic/metrics_collection_traffic_cache.go b/src/mapper/pkg/metrics_collection_traffic/metrics_collection_traffic_cache.go index 07f4f6e0..a7597aa2 100644 --- a/src/mapper/pkg/metrics_collection_traffic/metrics_collection_traffic_cache.go +++ b/src/mapper/pkg/metrics_collection_traffic/metrics_collection_traffic_cache.go @@ -11,6 +11,11 @@ import ( "github.com/spf13/viper" "golang.org/x/exp/slices" "hash/crc32" + "time" +) + +const ( + cacheTTL = 5 * time.Hour ) type CacheValue []byte @@ -21,9 +26,7 @@ type MetricsCollectionTrafficCache struct { func NewMetricsCollectionTrafficCache() *MetricsCollectionTrafficCache { size := viper.GetInt(config.MetricsCollectionTrafficCacheSizeKey) - // We don't want the cache to expire. It does not contain a lot of data, and we want to keep it as long as possible - // so we won't send unnecessary requests to the cloud. - cache := expirable.NewLRU[string, CacheValue](size, OnEvict, 0) + cache := expirable.NewLRU[string, CacheValue](size, OnEvict, cacheTTL) return &MetricsCollectionTrafficCache{ cache: cache, diff --git a/src/mapper/pkg/webhook_traffic/webhook_services_cache.go b/src/mapper/pkg/webhook_traffic/webhook_services_cache.go index e57b6133..d8587ded 100644 --- a/src/mapper/pkg/webhook_traffic/webhook_services_cache.go +++ b/src/mapper/pkg/webhook_traffic/webhook_services_cache.go @@ -14,6 +14,10 @@ import ( "time" ) +const ( + cacheTTL = 5 * time.Hour +) + type CacheValue []byte type WebhookServicesCache struct { @@ -22,7 +26,7 @@ type WebhookServicesCache struct { func NewWebhookServicesCache() *WebhookServicesCache { size := viper.GetInt(config.WebhookServicesCacheSizeKey) - cache := expirable.NewLRU[string, CacheValue](size, OnEvict, 5*time.Hour) + cache := expirable.NewLRU[string, CacheValue](size, OnEvict, cacheTTL) return &WebhookServicesCache{ cache: cache,