Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion src/mapper/pkg/webhook_traffic/webhook_services_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"time"
)

const (
cacheTTL = 5 * time.Hour
)

type CacheValue []byte

type WebhookServicesCache struct {
Expand All @@ -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,
Expand Down
Loading