Documentation ¶
Index ¶
- Constants
- type Cache
- func (c *Cache[K, V]) Delete(key K)
- func (c *Cache[K, V]) DeleteAll()
- func (c *Cache[K, V]) DeleteExpired()
- func (c *Cache[K, V]) Get(key K, opts ...Option[K, V]) *Item[K, V]
- func (c *Cache[K, V]) Items() map[K]*Item[K, V]
- func (c *Cache[K, V]) Keys() []K
- func (c *Cache[K, V]) Len() int
- func (c *Cache[K, V]) Metrics() Metrics
- func (c *Cache[K, V]) OnEviction(fn func(context.Context, EvictionReason, *Item[K, V])) func()
- func (c *Cache[K, V]) OnInsertion(fn func(context.Context, *Item[K, V])) func()
- func (c *Cache[K, V]) Set(key K, value V, ttl time.Duration) *Item[K, V]
- func (c *Cache[K, V]) Start()
- func (c *Cache[K, V]) Stop()
- func (c *Cache[K, V]) Touch(key K)
- type EvictionReason
- type Item
- type Loader
- type LoaderFunc
- type Metrics
- type Option
- type SuppressedLoader
Constants ¶
View Source
const ( // NoTTL indicates that an item should never expire. NoTTL time.Duration = -1 // DefaultTTL indicates that the default TTL // value should be used. DefaultTTL time.Duration = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
func (*Cache[K, V]) DeleteExpired ¶
func (c *Cache[K, V]) DeleteExpired()
func (*Cache[K, V]) OnEviction ¶
func (c *Cache[K, V]) OnEviction(fn func(context.Context, EvictionReason, *Item[K, V])) func()
func (*Cache[K, V]) OnInsertion ¶
type EvictionReason ¶
type EvictionReason int
const ( EvictionReasonDeleted EvictionReason = iota + 1 EvictionReasonExpired EvictionReasonCapacityReached )
type Item ¶
type Item[K comparable, V any] struct { // contains filtered or unexported fields }
Item holds all the information that is associated with a single cache value.
func (*Item[K, V]) IsExpired ¶
IsExpired returns a bool value that indicates whether the item is expired.
type Loader ¶
type Loader[K comparable, V any] interface { Load(c *Cache[K, V], key K) *Item[K, V] }
type LoaderFunc ¶
type LoaderFunc[K comparable, V any] func(*Cache[K, V], K) *Item[K, V]
func (LoaderFunc[K, V]) Load ¶
func (l LoaderFunc[K, V]) Load(c *Cache[K, V], key K) *Item[K, V]
type Option ¶
type Option[K comparable, V any] interface { // contains filtered or unexported methods }
func WithCapacity ¶
func WithCapacity[K comparable, V any](c uint64) Option[K, V]
func WithDisableTouchOnHit ¶
func WithDisableTouchOnHit[K comparable, V any]() Option[K, V]
func WithLoader ¶
func WithLoader[K comparable, V any](l Loader[K, V]) Option[K, V]
type SuppressedLoader ¶
type SuppressedLoader[K comparable, V any] struct { Loader[K, V] // contains filtered or unexported fields }
func (*SuppressedLoader[K, V]) Load ¶
func (l *SuppressedLoader[K, V]) Load(c *Cache[K, V], key K) *Item[K, V]
Click to show internal directories.
Click to hide internal directories.