Skip to content

Commit

Permalink
refactor: Make cache key static in memory
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Sep 17, 2022
1 parent 817e148 commit 6197850
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions pkg/ketchup/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/ViBiOh/ketchup/pkg/model"
)

var cacheVersion = sha.New("vibioh/ketchup/1")[:8]

func cachePrefix() string {
return "ketchup:" + cacheVersion
}
var (
cacheVersion = sha.New("vibioh/ketchup/1")[:8]
cachePrefix = "ketchup:" + cacheVersion
cacheSuggestsKey = cachePrefix + ":suggests"
)

func suggestCacheKey(user model.User) string {
if user.IsZero() {
return cachePrefix() + ":suggests"
return cacheSuggestsKey
}
return fmt.Sprintf("%s:user:%d:suggests", cachePrefix(), user.ID)
return fmt.Sprintf("%s:user:%d:suggests", cachePrefix, user.ID)
}
2 changes: 1 addition & 1 deletion pkg/ketchup/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ func (a App) cleanToken(ctx context.Context, token string) {
}

func tokenKey(token string) string {
return fmt.Sprintf("%s:token:%s", cachePrefix(), token)
return fmt.Sprintf("%s:token:%s", cachePrefix, token)
}

0 comments on commit 6197850

Please sign in to comment.