Skip to content

Commit

Permalink
perf: always cache meta tags 1h
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Nov 25, 2024
1 parent 4176a44 commit b532253
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/tag/cache_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func init() {
prometheus.MustRegister(TotalCount)
}

// also need to change version in [cachekey.SubjectMetaTag] if schema is changed.

func (r cacheRepo) Get(ctx context.Context, id model.SubjectID) ([]Tag, error) {
TotalCount.Add(1)
var key = cachekey.SubjectMetaTag(id)
Expand All @@ -90,14 +92,13 @@ func (r cacheRepo) Get(ctx context.Context, id model.SubjectID) ([]Tag, error) {
if e := r.cache.Set(ctx, key, cachedTags{
ID: id,
Tags: tags,
}, time.Minute); e != nil {
}, time.Hour); e != nil {
r.log.Error("can't set response to cache", zap.Error(e))
}

return tags, nil
}

// GetByIDs also need to change version in [cachekey.SubjectMetaTag] if schema is changed.
func (r cacheRepo) GetByIDs(ctx context.Context, ids []model.SubjectID) (map[model.SubjectID][]Tag, error) {
TotalCount.Add(float64(len(ids)))

Expand Down

0 comments on commit b532253

Please sign in to comment.