Refactor caching logic and add support for a new feature
Some checks failed
🚨 Test Code Base / 🧹 Lint (push) Failing after 5m24s
🚨 Test Code Base / 🔍 🐹 Go Tests (push) Failing after 5m45s
🏗️✨ Build Workflow / 🖥️ 🔨 Build (push) Failing after 6m14s

This commit is contained in:
2026-01-21 21:08:26 -05:00
parent 838051c880
commit d321d96fef
6 changed files with 128 additions and 94 deletions

View File

@@ -16,6 +16,7 @@ type contextKey string
const redisKey contextKey = "redisClient"
const CacheKey = "top-wallpaper:latestImage"
const NsfwCacheKey = "top-wallpaper-nsfw:latestImage"
type Cache interface {
Get(key string) (string, error)
@@ -92,6 +93,14 @@ func (r *Redis) Set(key string, value string, expiration time.Duration) error {
return nil
}
func (*Redis) GetCacheKey(nsfw bool) string {
if nsfw {
return NsfwCacheKey
}
return CacheKey
}
func (r *Redis) Close() error {
if r.client == nil {
return nil