Documentation
¶
Index ¶
- Constants
- type Any
- func New[K comparable, V any](defaultExpiration, cleanupInterval time.Duration) *Any[K, V]
- func NewAny[K comparable, V any](defaultExpiration, cleanupInterval time.Duration) *Any[K, V]
- func NewAnyFrom[K comparable, V any](defaultExpiration, cleanupInterval time.Duration, items map[K]Item[V]) *Any[K, V]
- func NewFrom[K comparable, V any](defaultExpiration, cleanupInterval time.Duration, items map[K]Item[V]) *Any[K, V]
- func (c Any) Add(k K, v V, d time.Duration) error
- func (c Any) Delete(k K)
- func (c Any) DeleteAll()
- func (c Any) DeleteBySlice(ks []K)
- func (c Any) DeleteExpired()
- func (c Any) Flush()
- func (c Any) Get(k K) (V, bool)
- func (c Any) GetWithExpiration(k K) (V, time.Time, bool)
- func (c Any) GetWithHit(k K) (V, int, bool)
- func (c Any) GetWithHitExpiration(k K) (V, int, time.Time, bool)
- func (c Any) GetsByMap(in map[K]V) (map[K]V, bool)
- func (c Any) GetsBySlice(ks []K) ([]V, bool)
- func (c Any) ItemCount() int
- func (c Any) Items() map[K]Item[V]
- func (c Any) Load(r io.Reader) error
- func (c Any) LoadFile(fname string) error
- func (c Any) OnEvicted(f func(key K, value V, hit int))
- func (c Any) Replace(k K, x V, d time.Duration) error
- func (c Any) Save(w io.Writer) (err error)
- func (c Any) SaveFile(fname string) error
- func (c Any) Set(k K, v V, d time.Duration)
- func (c Any) SetDefault(k K, v V)
- func (c Any) SetJanitor(j *janitor)
- func (c Any) SetsByMap(data map[K]V, d time.Duration)
- func (c Any) SetsBySlice(data []V, d time.Duration, handle func(V) (k K, v V))
- func (c Any) StopJanitor()
- func (c Any) UpdateExpiration(k K, d time.Duration) error
- type Item
- type Number
- func (c Number) Add(k K, v V, d time.Duration) error
- func (c *Number[K, V]) Decrement(k K, n V) error
- func (c Number) Delete(k K)
- func (c Number) DeleteAll()
- func (c Number) DeleteBySlice(ks []K)
- func (c Number) DeleteExpired()
- func (c Number) Flush()
- func (c Number) Get(k K) (V, bool)
- func (c Number) GetWithExpiration(k K) (V, time.Time, bool)
- func (c Number) GetWithHit(k K) (V, int, bool)
- func (c Number) GetWithHitExpiration(k K) (V, int, time.Time, bool)
- func (c Number) GetsByMap(in map[K]V) (map[K]V, bool)
- func (c Number) GetsBySlice(ks []K) ([]V, bool)
- func (c *Number[K, V]) Increment(k K, n V) error
- func (c Number) ItemCount() int
- func (c Number) Items() map[K]Item[V]
- func (c Number) Load(r io.Reader) error
- func (c Number) LoadFile(fname string) error
- func (c Number) OnEvicted(f func(key K, value V, hit int))
- func (c Number) Replace(k K, x V, d time.Duration) error
- func (c Number) Save(w io.Writer) (err error)
- func (c Number) SaveFile(fname string) error
- func (c Number) Set(k K, v V, d time.Duration)
- func (c Number) SetDefault(k K, v V)
- func (c Number) SetJanitor(j *janitor)
- func (c *Number[K, V]) SetMax(k K, v V, d time.Duration) error
- func (c *Number[K, V]) SetMin(k K, v V, d time.Duration) error
- func (c Number) SetsByMap(data map[K]V, d time.Duration)
- func (c Number) SetsBySlice(data []V, d time.Duration, handle func(V) (k K, v V))
- func (c Number) StopJanitor()
- func (c Number) UpdateExpiration(k K, d time.Duration) error
- func (c *Number[K, V]) UpdateMax(k K, v V) error
- func (c *Number[K, V]) UpdateMin(k K, v V) error
Constants ¶
const ( // NoExpiration Item has no expiration date NoExpiration time.Duration = -1 // DefaultExpiration Equivalent to passing in the same expiration duration as was given to New() or NewFrom() // when the cache was created (e.g. 5 minutes.) DefaultExpiration time.Duration = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Any ¶
type Any[K comparable, V any] struct { // contains filtered or unexported fields }
func New ¶
func New[K comparable, V any](defaultExpiration, cleanupInterval time.Duration) *Any[K, V]
func NewAny ¶
func NewAny[K comparable, V any](defaultExpiration, cleanupInterval time.Duration) *Any[K, V]
func NewAnyFrom ¶
func (Any) Add ¶
Add an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired. Returns an error otherwise.
func (Any) Delete ¶
func (c Any) Delete(k K)
Delete an item from the cache. Does nothing if the key is not in the cache.
func (Any) DeleteBySlice ¶ added in v0.0.5
func (c Any) DeleteBySlice(ks []K)
DeleteBySlice an item from the cache. Does nothing if the key is not in the cache.
func (Any) Get ¶
func (c Any) Get(k K) (V, bool)
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Any) GetWithExpiration ¶
GetWithExpiration returns an item and its expiration time from the cache. It returns the item or nil, the expiration time if one is set (if the item never expires a zero value for time.Time is returned), and a bool indicating whether the key was found.
func (Any) GetWithHit ¶
func (Any) GetsByMap ¶ added in v0.0.4
func (c Any) GetsByMap(in map[K]V) (map[K]V, bool)
GetsByMap items from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Any) GetsBySlice ¶ added in v0.0.4
func (c Any) GetsBySlice(ks []K) ([]V, bool)
GetsBySlice items from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Any) ItemCount ¶
func (c Any) ItemCount() int
Returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up.
func (Any) Items ¶
func (c Any) Items() map[K]Item[V]
Copies all unexpired items in the cache into a new map and returns it.
func (Any) Load ¶
Add (Gob-serialized) cache items from an io.Reader, excluding any items with keys that already exist (and haven't expired) in the current cache.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Any) LoadFile ¶
Load and add cache items from the given filename, excluding any items with keys that already exist in the current cache.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Any) Replace ¶
Set a new value for the cache key only if it already exists, and the existing item hasn't expired. Returns an error otherwise.
func (Any) Save ¶
Save Write the cache's items (using Gob) to an io.Writer.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Any) SaveFile ¶
Save the cache's items to the given filename, creating the file if it doesn't exist, and overwriting it if it does.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Any) Set ¶
Set Add an item to the cache, replacing any existing item. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
func (Any) SetDefault ¶
func (c Any) SetDefault(k K, v V)
SetDefault Add an item to the cache, replacing any existing item, using the default expiration.
func (Any) SetJanitor ¶
func (c Any) SetJanitor(j *janitor)
func (Any) SetsByMap ¶ added in v0.0.4
SetsByMap Add items to the cache, replacing any existing item. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
func (Any) SetsBySlice ¶ added in v0.0.4
SetsBySlice Add items to the cache, replacing any existing item. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
func (Any) StopJanitor ¶
func (c Any) StopJanitor()
func (Any) UpdateExpiration ¶
UpdateExpiration. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
type Number ¶
type Number[K comparable, V number] struct { // contains filtered or unexported fields }
func NewNumber ¶
func NewNumber[K comparable, V number](defaultExpiration, cleanupInterval time.Duration) *Number[K, V]
func NewNumberFrom ¶
func NewNumberFrom[K comparable, V number](defaultExpiration, cleanupInterval time.Duration, items map[K]Item[V]) *Number[K, V]
func (Number) Add ¶
Add an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired. Returns an error otherwise.
func (*Number[K, V]) Decrement ¶
Decrement an item by n. Returns an error if the item's value is not an integer, if it was not found, or if it is not possible to decrement it by n. To retrieve the decremented value, use one of the specialized methods, e.g. DecrementInt64.
func (Number) Delete ¶
func (c Number) Delete(k K)
Delete an item from the cache. Does nothing if the key is not in the cache.
func (Number) DeleteBySlice ¶ added in v0.0.5
func (c Number) DeleteBySlice(ks []K)
DeleteBySlice an item from the cache. Does nothing if the key is not in the cache.
func (Number) DeleteExpired ¶
func (c Number) DeleteExpired()
DeleteExpired delete all expired items
func (Number) Get ¶
func (c Number) Get(k K) (V, bool)
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Number) GetWithExpiration ¶
GetWithExpiration returns an item and its expiration time from the cache. It returns the item or nil, the expiration time if one is set (if the item never expires a zero value for time.Time is returned), and a bool indicating whether the key was found.
func (Number) GetWithHit ¶
func (Number) GetWithHitExpiration ¶
func (Number) GetsByMap ¶ added in v0.0.4
func (c Number) GetsByMap(in map[K]V) (map[K]V, bool)
GetsByMap items from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Number) GetsBySlice ¶ added in v0.0.4
func (c Number) GetsBySlice(ks []K) ([]V, bool)
GetsBySlice items from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (*Number[K, V]) Increment ¶
Increment an item by n. Returns an error if the item's value is not an integer, if it was not found, or if it is not possible to increment it by n. To retrieve the incremented value, use one of the specialized methods, e.g. IncrementInt64.
func (Number) ItemCount ¶
func (c Number) ItemCount() int
Returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up.
func (Number) Items ¶
func (c Number) Items() map[K]Item[V]
Copies all unexpired items in the cache into a new map and returns it.
func (Number) Load ¶
Add (Gob-serialized) cache items from an io.Reader, excluding any items with keys that already exist (and haven't expired) in the current cache.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Number) LoadFile ¶
Load and add cache items from the given filename, excluding any items with keys that already exist in the current cache.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Number) Replace ¶
Set a new value for the cache key only if it already exists, and the existing item hasn't expired. Returns an error otherwise.
func (Number) Save ¶
Save Write the cache's items (using Gob) to an io.Writer.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Number) SaveFile ¶
Save the cache's items to the given filename, creating the file if it doesn't exist, and overwriting it if it does.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Number) Set ¶
Set Add an item to the cache, replacing any existing item. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
func (Number) SetDefault ¶
func (c Number) SetDefault(k K, v V)
SetDefault Add an item to the cache, replacing any existing item, using the default expiration.
func (Number) SetJanitor ¶
func (c Number) SetJanitor(j *janitor)
func (*Number[K, V]) SetMax ¶
SetMax Update Value to the maximum value. Create it if it does not exist. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
func (*Number[K, V]) SetMin ¶
SetMin Update Value to the minimum value. Create it if it does not exist. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
func (Number) SetsByMap ¶ added in v0.0.4
SetsByMap Add items to the cache, replacing any existing item. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
func (Number) SetsBySlice ¶ added in v0.0.4
SetsBySlice Add items to the cache, replacing any existing item. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
func (Number) StopJanitor ¶
func (c Number) StopJanitor()
func (Number) UpdateExpiration ¶
UpdateExpiration. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.