mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2026-01-03 11:23:16 -06:00
use ttlcache
This commit is contained in:
parent
73fc5cf2f0
commit
cf1dcdf46a
7 changed files with 15 additions and 66 deletions
15
internal/cache/cache.go
vendored
15
internal/cache/cache.go
vendored
|
|
@ -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{}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue