mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-16 04:24:56 +02:00
Adding app/cache/cache.go
This commit is contained in:
parent
c6cb26d543
commit
2eb62db117
1 changed files with 30 additions and 0 deletions
30
app/cache/cache.go
vendored
Normal file
30
app/cache/cache.go
vendored
Normal file
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue