mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2026-01-06 00:53:16 -06:00
and yet more
This commit is contained in:
parent
896461dec3
commit
702d534136
15 changed files with 375 additions and 35 deletions
23
internal/cache/cache.go
vendored
23
internal/cache/cache.go
vendored
|
|
@ -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{}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue