Skip to content

Commit a4493c8

Browse files
feat: increase cache duration
1 parent f404fc1 commit a4493c8

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

internal/server/cache.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"net/http"
66
"strings"
7+
"time"
78

89
"github.com/patrickmn/go-cache"
910
)
@@ -35,8 +36,12 @@ func (s *Server) getFromCache(k cacheKey) (any, bool) {
3536
return s.cache.Get(string(k))
3637
}
3738

38-
func (s *Server) setInCache(k cacheKey, v any) {
39-
s.cache.Set(string(k), v, cache.DefaultExpiration)
39+
func (s *Server) setInCache(k cacheKey, v any, expiration ...time.Duration) {
40+
exp := cache.DefaultExpiration
41+
if len(expiration) > 0 {
42+
exp = expiration[0]
43+
}
44+
s.cache.Set(string(k), v, exp)
4045
}
4146

4247
func (s *Server) invalidateByPrefix(prefix cacheKey) {

internal/server/handler_download.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net/http"
77
"strings"
8+
"time"
89

910
"github.com/go-chi/chi/v5"
1011
"github.com/google/go-github/v50/github"
@@ -27,7 +28,7 @@ func (s *Server) getLatestSemRelRelease(ctx context.Context) (*github.Repository
2728
if err != nil {
2829
return nil, err
2930
}
30-
s.setInCache(semrelCacheKey, latestRelease)
31+
s.setInCache(semrelCacheKey, latestRelease, time.Minute*30)
3132
return latestRelease, nil
3233
}
3334

internal/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func New(log *logrus.Logger, db *firestore.Client, ghClient *github.Client, stor
7979
ghClient: ghClient,
8080
storage: storage,
8181
config: serverCfg,
82-
cache: cache.New(5*time.Minute, 10*time.Minute),
82+
cache: cache.New(15*time.Minute, 30*time.Minute),
8383
ghSemaphore: semaphore.NewWeighted(1),
8484
batchArchiveSemaphore: semaphore.NewWeighted(1),
8585
}

0 commit comments

Comments
 (0)