Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalidMaxSize is returned when the given max size is not positive. ErrInvalidMaxSize = errors.New("max size must be > 0") )
Functions ¶
This section is empty.
Types ¶
type LRUExpireCache ¶
type LRUExpireCache[K comparable, V any] struct { // contains filtered or unexported fields }
LRUExpireCache is a cache that ensures the mostly recently accessed keys are returned with a ttl beyond which keys are forcibly expired.
func NewLRUExpireCache ¶
func NewLRUExpireCache[K comparable, V any](maxSize int) (*LRUExpireCache[K, V], error)
NewLRUExpireCache creates an expiring cache with the given size
func (*LRUExpireCache[K, V]) Add ¶
func (c *LRUExpireCache[K, V]) Add( key K, value V, ttl time.Duration, )
Add adds the value to the cache at key with the specified maximum duration.
func (*LRUExpireCache[K, V]) Get ¶
func (c *LRUExpireCache[K, V]) Get(key K) (V, bool)
Get returns the value at the specified key from the cache if it exists and is not expired, or returns false.
Click to show internal directories.
Click to hide internal directories.