An atproto PDS written in Go
at v0.5.1 1.0 kB view raw
1package identity 2 3import ( 4 "time" 5 6 "github.com/hashicorp/golang-lru/v2/expirable" 7) 8 9type MemCache struct { 10 docCache *expirable.LRU[string, *DidDoc] 11 didCache *expirable.LRU[string, string] 12} 13 14func NewMemCache(size int) *MemCache { 15 docCache := expirable.NewLRU[string, *DidDoc](size, nil, 5*time.Minute) 16 didCache := expirable.NewLRU[string, string](size, nil, 5*time.Minute) 17 18 return &MemCache{ 19 docCache: docCache, 20 didCache: didCache, 21 } 22} 23 24func (mc *MemCache) GetDoc(did string) (*DidDoc, bool) { 25 return mc.docCache.Get(did) 26} 27 28func (mc *MemCache) PutDoc(did string, doc *DidDoc) error { 29 mc.docCache.Add(did, doc) 30 return nil 31} 32 33func (mc *MemCache) BustDoc(did string) error { 34 mc.docCache.Remove(did) 35 return nil 36} 37 38func (mc *MemCache) GetDid(handle string) (string, bool) { 39 return mc.didCache.Get(handle) 40} 41 42func (mc *MemCache) PutDid(handle string, did string) error { 43 mc.didCache.Add(handle, did) 44 return nil 45} 46 47func (mc *MemCache) BustDid(handle string) error { 48 mc.didCache.Remove(handle) 49 return nil 50}