Something went wrong. Try again.
(READ ONLY) Margin is an open annotation layer for the internet. Powered by the AT Protocol.
margin.at
extension web atproto comments
Something went wrong. Try again.
Go
at ui-refactor
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849package api
import ( "sync" "time")
type ProfileCache interface { Get(did string) (Author, bool) Set(did string, profile Author)}type InMemoryCache struct { cache sync.Map ttl time.Duration}
type cachedProfile struct { Author Author ExpiresAt time.Time}
func NewInMemoryCache(ttl time.Duration) *InMemoryCache { return &InMemoryCache{ ttl: ttl, }}
func (c *InMemoryCache) Get(did string) (Author, bool) { val, ok := c.cache.Load(did) if !ok { return Author{}, false }
entry := val.(cachedProfile) if time.Now().After(entry.ExpiresAt) { c.cache.Delete(did) return Author{}, false }
return entry.Author, true}
func (c *InMemoryCache) Set(did string, profile Author) { c.cache.Store(did, cachedProfile{ Author: profile, ExpiresAt: time.Now().Add(c.ttl), })}