Create a cache package
All checks were successful
ci/woodpecker/push/build Pipeline was successful

Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
This commit is contained in:
2026-05-17 22:29:16 +02:00
parent 1ca66a885b
commit 732f70238a
3 changed files with 97 additions and 9 deletions

View File

@@ -1 +1,25 @@
package cache
import (
"context"
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
const (
CacheFolderToken = "token"
)
func buildKey(folder, key string) string {
return fmt.Sprintf("%s:%s", folder, key)
}
func GetFromCache(ctx context.Context, redis *redis.Client, folder, key string) string {
return redis.Get(ctx, buildKey(folder, key)).Val()
}
func SaveToCache(ctx context.Context, redis *redis.Client, folder, key, value string, ttl time.Duration) error {
return redis.Set(ctx, buildKey(folder, key), value, ttl).Err()
}