Something went wrong. Try again.
Monorepo for Tangled
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536package pages
import ( "sync")
type TmplCache[K comparable, V any] struct { data map[K]V mutex sync.RWMutex}
func NewTmplCache[K comparable, V any]() *TmplCache[K, V] { return &TmplCache[K, V]{ data: make(map[K]V), }}
func (c *TmplCache[K, V]) Get(key K) (V, bool) { c.mutex.RLock() defer c.mutex.RUnlock() val, exists := c.data[key] return val, exists}
func (c *TmplCache[K, V]) Set(key K, value V) { c.mutex.Lock() defer c.mutex.Unlock() c.data[key] = value}
func (c *TmplCache[K, V]) Size() int { c.mutex.RLock() defer c.mutex.RUnlock() return len(c.data)}