and yet more

This commit is contained in:
tsmethurst 2021-08-18 14:21:19 +02:00
commit 702d534136
15 changed files with 375 additions and 35 deletions

View file

@ -18,8 +18,31 @@
package cache
import (
"sync"
"time"
)
// Cache defines an in-memory cache that is safe to be wiped when the application is restarted
type Cache interface {
Store(k string, v interface{}) error
Fetch(k string) (interface{}, error)
}
type cache struct {
stored *sync.Map
}
// New returns a new in-memory cache.
func New() Cache {
cache := &cache{
stored: &sync.Map{},
}
go cache.sweep()
return cache
}
type cacheEntry struct {
updated time.Time
value interface{}
}