Skip to content

Commit

Permalink
feat: increase cache duration
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Feb 6, 2023
1 parent f404fc1 commit a4493c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions internal/server/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"strings"
"time"

"github.com/patrickmn/go-cache"
)
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion internal/server/handler_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"strings"
"time"

"github.com/go-chi/chi/v5"
"github.com/google/go-github/v50/github"
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

0 comments on commit a4493c8

Please sign in to comment.