Something went wrong. Try again.
A fork of the Cocoon PDS but being made more distributed. forked from willdot.net/cocoon
Something went wrong. Try again.
1.0 kB · 50 lines
Go
at 2fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051package identity
import ( "time"
"github.com/hashicorp/golang-lru/v2/expirable")
type MemCache struct { docCache *expirable.LRU[string, *DidDoc] didCache *expirable.LRU[string, string]}
func NewMemCache(size int) *MemCache { docCache := expirable.NewLRU[string, *DidDoc](size, nil, 5*time.Minute) didCache := expirable.NewLRU[string, string](size, nil, 5*time.Minute)
return &MemCache{ docCache: docCache, didCache: didCache, }}
func (mc *MemCache) GetDoc(did string) (*DidDoc, bool) { return mc.docCache.Get(did)}
func (mc *MemCache) PutDoc(did string, doc *DidDoc) error { mc.docCache.Add(did, doc) return nil}
func (mc *MemCache) BustDoc(did string) error { mc.docCache.Remove(did) return nil}
func (mc *MemCache) GetDid(handle string) (string, bool) { return mc.didCache.Get(handle)}
func (mc *MemCache) PutDid(handle string, did string) error { mc.didCache.Add(handle, did) return nil}
func (mc *MemCache) BustDid(handle string) error { mc.didCache.Remove(handle) return nil}