use ttlcache

This commit is contained in:
tsmethurst 2021-08-19 16:16:16 +02:00
commit cf1dcdf46a
7 changed files with 15 additions and 66 deletions

View file

@ -19,8 +19,9 @@
package cache
import (
"sync"
"time"
"github.com/ReneKroon/ttlcache"
)
// Cache defines an in-memory cache that is safe to be wiped when the application is restarted
@ -30,19 +31,15 @@ type Cache interface {
}
type cache struct {
stored *sync.Map
c *ttlcache.Cache
}
// New returns a new in-memory cache.
func New() Cache {
c := ttlcache.NewCache()
c.SetTTL(30 * time.Second)
cache := &cache{
stored: &sync.Map{},
c: c,
}
go cache.sweep()
return cache
}
type cacheEntry struct {
updated time.Time
value interface{}
}