diff --git a/internal/server/cache.go b/internal/server/cache.go index be11037..4a5ff21 100644 --- a/internal/server/cache.go +++ b/internal/server/cache.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "strings" + "time" "github.com/patrickmn/go-cache" ) @@ -35,8 +36,12 @@ func (s *Server) getFromCache(k cacheKey) (any, bool) { return s.cache.Get(string(k)) } -func (s *Server) setInCache(k cacheKey, v any) { - s.cache.Set(string(k), v, cache.DefaultExpiration) +func (s *Server) setInCache(k cacheKey, v any, expiration ...time.Duration) { + exp := cache.DefaultExpiration + if len(expiration) > 0 { + exp = expiration[0] + } + s.cache.Set(string(k), v, exp) } func (s *Server) invalidateByPrefix(prefix cacheKey) { diff --git a/internal/server/handler_download.go b/internal/server/handler_download.go index bde3e5f..711bf1a 100644 --- a/internal/server/handler_download.go +++ b/internal/server/handler_download.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "strings" + "time" "github.com/go-chi/chi/v5" "github.com/google/go-github/v50/github" @@ -27,7 +28,7 @@ func (s *Server) getLatestSemRelRelease(ctx context.Context) (*github.Repository if err != nil { return nil, err } - s.setInCache(semrelCacheKey, latestRelease) + s.setInCache(semrelCacheKey, latestRelease, time.Minute*30) return latestRelease, nil } diff --git a/internal/server/server.go b/internal/server/server.go index eafa108..84d05f4 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -79,7 +79,7 @@ func New(log *logrus.Logger, db *firestore.Client, ghClient *github.Client, stor ghClient: ghClient, storage: storage, config: serverCfg, - cache: cache.New(5*time.Minute, 10*time.Minute), + cache: cache.New(15*time.Minute, 30*time.Minute), ghSemaphore: semaphore.NewWeighted(1), batchArchiveSemaphore: semaphore.NewWeighted(1), }