Documentation
¶
Index ¶
- Variables
- func DefaultOnExpire[D any](D)
- type Cache
- func (c *Cache[K, D]) CheckExpirations(now time.Time)
- func (c *Cache[K, D]) Load(key K) (actual *Element[D])
- func (c *Cache[K, D]) LoadOrStore(key K, e *Element[D]) (actual *Element[D], loaded bool)
- func (c *Cache[K, D]) LoadOrStoreWithLimit(key K, e *Element[D], maxEntries int) (actual *Element[D], loaded bool, err error)
- type Element
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCacheFull = errors.New("cache is full")
Functions ¶
func DefaultOnExpire ¶
func DefaultOnExpire[D any](D)
Types ¶
type Cache ¶
type Cache[K comparable, D any] struct { *sync.Map[K, *Element[D]] }
func NewCache ¶
func NewCache[K comparable, D any]() *Cache[K, D]
func (*Cache[K, D]) CheckExpirations ¶
func (*Cache[K, D]) LoadOrStore ¶
func (*Cache[K, D]) LoadOrStoreWithLimit ¶ added in v3.5.7
func (c *Cache[K, D]) LoadOrStoreWithLimit(key K, e *Element[D], maxEntries int) (actual *Element[D], loaded bool, err error)
LoadOrStoreWithLimit loads an unexpired entry or atomically stores e if there is capacity. A non-positive maxEntries means unlimited. Expired entries are reclaimed when the cache is full. Existing entries can be loaded at capacity.
type Element ¶
func NewElement ¶
Click to show internal directories.
Click to hide internal directories.