Something went wrong. Try again.
Fetch, resize, reformat, and cache Atmosphere avatar images atp.pics
atproto
Something went wrong. Try again.
Go
1234567891011121314151617181920212223242526272829303132333435363738// Package cache provides a lightweight in-process TTL cache for DID → avatar CID mappings.package cache
import ( "sync" "time")
const ttl = 5 * time.Minute
type entry struct { cid string mimeType string expiry time.Time}
// CIDCache caches DID → (avatar CID, mimeType) with a fixed 5-minute TTL.type CIDCache struct { m sync.Map}
func (c *CIDCache) Get(did string) (cid, mimeType string, ok bool) { v, ok := c.m.Load(did) if !ok { return "", "", false } e := v.(entry) if time.Now().After(e.expiry) { c.m.Delete(did) return "", "", false } return e.cid, e.mimeType, true}
func (c *CIDCache) Set(did, cid, mimeType string) { c.m.Store(did, entry{cid: cid, mimeType: mimeType, expiry: time.Now().Add(ttl)})}