// 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)}) }