From 2eb62db117aeec4a09774e2602925ba9dae4d1bd Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 1 Nov 2023 21:23:48 +0100 Subject: [PATCH] Adding app/cache/cache.go --- app/cache/cache.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 app/cache/cache.go diff --git a/app/cache/cache.go b/app/cache/cache.go new file mode 100644 index 0000000..290019b --- /dev/null +++ b/app/cache/cache.go @@ -0,0 +1,30 @@ +package cache + +import ( + "time" +) + +type Cache struct { + store Store + prefix string +} + +// Create a new cache +func NewCache(prefix string, store Store) *Cache { + return &Cache{ + store: store, + prefix: prefix, + } +} + +func (cache *Cache) Get(key string, value any) error { + return cache.store.Get(cache.key(key), value) +} + +func (cache *Cache) Set(key string, value any, ttl time.Duration) error { + return cache.store.Set(cache.key(key), value, ttl) +} + +func (cache *Cache) key(key string) string { + return cache.prefix + "::" + key +}