Documentation ¶
Index ¶
- Constants
- type Cache
- func (c Cache) Add(k K, x T, d time.Duration) error
- func (c Cache) Decrement(k K, n int64) (T, error)
- func (c Cache) Delete(k K)
- func (c Cache) DeleteExpired()
- func (c Cache) DeleteRegex(rule string)
- func (c Cache) Edit(k K, x interface{}, apFunc func(T, interface{}) (T, error)) error
- func (c Cache) Flush()
- func (c Cache) Get(k K) (T, bool)
- func (c Cache) GetMultipleItems(keys []K) []T
- func (c Cache) GetOrCreateNew(k K) (T, bool)
- func (c Cache) GetRandom() (key K, val T, b bool)
- func (c Cache) GetRandomThenDelete() (key K, val T, b bool)
- func (c Cache) GetThenDelete(k K) (T, bool)
- func (c Cache) GetWithDefaultExpirationUpdate(k K) (T, bool)
- func (c Cache) GetWithExpiration(k K) (T, time.Time, bool)
- func (c Cache) GetWithExpirationUpdate(k K, d time.Duration) (T, bool)
- func (c Cache) Increment(k K, n int64) (T, error)
- func (c Cache) IncrementExpiration(k K, d time.Duration) error
- func (c Cache) ItemCount() int
- func (c Cache) Items() map[K]Item[T]
- func (c Cache) Iterate(f func(key K, item T) bool) bool
- func (c Cache) Keys() []K
- func (c Cache) Length() int
- func (c Cache) Load(r io.Reader) error
- func (c Cache) LoadFile(fname string) error
- func (c Cache) OnEvicted(f func(K, T))
- func (c Cache) Replace(k K, x T, d time.Duration) error
- func (c Cache) Save(w io.Writer) (err error)
- func (c Cache) SaveFile(fname string) error
- func (c Cache) Set(k K, x T, d time.Duration)
- func (c Cache) SetDefault(k K, x T)
- func (c *Cache[K, T]) SetNextCheckExpireate(d time.Duration)
- func (c Cache) Values() []T
- type CacheFiles
- func (c CacheFiles) Add(k K, x T, d time.Duration) error
- func (c CacheFiles) Decrement(k K, n int64) (T, error)
- func (c CacheFiles) Delete(k K)
- func (c CacheFiles) DeleteExpired()
- func (c CacheFiles) DeleteRegex(rule string)
- func (c CacheFiles) Edit(k K, x interface{}, apFunc func(T, interface{}) (T, error)) error
- func (c CacheFiles) Flush()
- func (c CacheFiles) Get(k K) (T, bool)
- func (cf *CacheFiles) GetCacheFile(fname string) (string, bool)
- func (cf *CacheFiles) GetCacheFileContent(fname string) (content []byte, err error)
- func (cf *CacheFiles) GetCacheFileContentString(fname string) (string, error)
- func (cf *CacheFiles) GetCacheFileOrCreate(fname string) (pathCacheFile string, isOldFile bool)
- func (cf *CacheFiles) GetCacheFileOrCreateWithExpiration(fname string, d time.Duration) (pathCacheFile string, isOldFile bool)
- func (cf *CacheFiles) GetCacheFromUrl(fname, url, user, password string) (pathCacheFile string, err error)
- func (c CacheFiles) GetMultipleItems(keys []K) []T
- func (c CacheFiles) GetOrCreateNew(k K) (T, bool)
- func (c CacheFiles) GetRandom() (key K, val T, b bool)
- func (c CacheFiles) GetRandomThenDelete() (key K, val T, b bool)
- func (c CacheFiles) GetThenDelete(k K) (T, bool)
- func (c CacheFiles) GetWithDefaultExpirationUpdate(k K) (T, bool)
- func (c CacheFiles) GetWithExpiration(k K) (T, time.Time, bool)
- func (c CacheFiles) GetWithExpirationUpdate(k K, d time.Duration) (T, bool)
- func (c CacheFiles) Increment(k K, n int64) (T, error)
- func (c CacheFiles) IncrementExpiration(k K, d time.Duration) error
- func (c CacheFiles) ItemCount() int
- func (c CacheFiles) Items() map[K]Item[T]
- func (c CacheFiles) Iterate(f func(key K, item T) bool) bool
- func (c CacheFiles) Keys() []K
- func (c CacheFiles) Length() int
- func (c CacheFiles) Load(r io.Reader) error
- func (c CacheFiles) LoadFile(fname string) error
- func (c CacheFiles) OnEvicted(f func(K, T))
- func (c CacheFiles) Replace(k K, x T, d time.Duration) error
- func (c CacheFiles) Save(w io.Writer) (err error)
- func (c CacheFiles) SaveFile(fname string) error
- func (c CacheFiles) Set(k K, x T, d time.Duration)
- func (c CacheFiles) SetDefault(k K, x T)
- func (c CacheFiles) Values() []T
- type CacheFuncs
- func (c CacheFuncs) Add(k K, x T, d time.Duration) error
- func (cf *CacheFuncs) AddFunc(fname string, f interface{}, params ...interface{}) (task *funcmap.Task[string], err error)
- func (cf *CacheFuncs) AddFuncIfNotExist(fname string, f interface{}, params ...interface{}) (task *funcmap.Task[string], err error)
- func (cf *CacheFuncs) CallFunc(fname string) (results []interface{}, err error)
- func (c CacheFuncs) Decrement(k K, n int64) (T, error)
- func (c CacheFuncs) Delete(k K)
- func (c CacheFuncs) DeleteExpired()
- func (c CacheFuncs) DeleteRegex(rule string)
- func (c CacheFuncs) Edit(k K, x interface{}, apFunc func(T, interface{}) (T, error)) error
- func (c CacheFuncs) Flush()
- func (c CacheFuncs) Get(k K) (T, bool)
- func (cf *CacheFuncs) GetFunc(fname string) (*funcmap.Task[string], bool)
- func (c CacheFuncs) GetMultipleItems(keys []K) []T
- func (c CacheFuncs) GetOrCreateNew(k K) (T, bool)
- func (c CacheFuncs) GetRandom() (key K, val T, b bool)
- func (c CacheFuncs) GetRandomThenDelete() (key K, val T, b bool)
- func (c CacheFuncs) GetThenDelete(k K) (T, bool)
- func (c CacheFuncs) GetWithDefaultExpirationUpdate(k K) (T, bool)
- func (c CacheFuncs) GetWithExpiration(k K) (T, time.Time, bool)
- func (c CacheFuncs) GetWithExpirationUpdate(k K, d time.Duration) (T, bool)
- func (c CacheFuncs) Increment(k K, n int64) (T, error)
- func (c CacheFuncs) IncrementExpiration(k K, d time.Duration) error
- func (c CacheFuncs) ItemCount() int
- func (c CacheFuncs) Items() map[K]Item[T]
- func (c CacheFuncs) Iterate(f func(key K, item T) bool) bool
- func (c CacheFuncs) Keys() []K
- func (c CacheFuncs) Length() int
- func (c CacheFuncs) Load(r io.Reader) error
- func (c CacheFuncs) LoadFile(fname string) error
- func (c CacheFuncs) OnEvicted(f func(K, T))
- func (c CacheFuncs) Replace(k K, x T, d time.Duration) error
- func (c CacheFuncs) Save(w io.Writer) (err error)
- func (c CacheFuncs) SaveFile(fname string) error
- func (c CacheFuncs) Set(k K, x T, d time.Duration)
- func (c CacheFuncs) SetDefault(k K, x T)
- func (c CacheFuncs) Values() []T
- type CachePools
- func (sc *CachePools[K, T]) Add(k K, x T, d time.Duration) error
- func (sc *CachePools[K, T]) Decrement(k K, n int64) error
- func (sc *CachePools[K, T]) Delete(k K)
- func (sc *CachePools[K, T]) DeleteExpired()
- func (sc *CachePools[K, T]) Edit(k K, x interface{}, apFunc func(T, interface{}) (T, error)) error
- func (sc *CachePools[K, T]) Flush()
- func (sc *CachePools[K, T]) Get(k K) (T, bool)
- func (sc *CachePools[K, T]) GetWithDefaultExpirationUpdate(k K) (T, bool)
- func (sc *CachePools[K, T]) GetWithExpirationGet(k K) (T, time.Time, bool)
- func (sc *CachePools[K, T]) GetWithExpirationUpdate(k K, d time.Duration) (T, bool)
- func (sc *CachePools[K, T]) Increment(k K, n int64) error
- func (sc *CachePools[K, T]) Items() []map[K]Item[T]
- func (sc *CachePools[K, T]) Keys() (keys []K)
- func (sc *CachePools[K, T]) Load(r io.Reader) error
- func (sc *CachePools[K, T]) LoadFile(fname string) error
- func (sc *CachePools[K, T]) Replace(k K, x T, d time.Duration) error
- func (sc *CachePools[K, T]) Save(w io.Writer) (err error)
- func (sc *CachePools[K, T]) SaveFile(fname string) error
- func (sc *CachePools[K, T]) Set(k K, x T, d time.Duration)
- func (sc *CachePools[K, T]) SetDefault(k K, x T)
- type Item
- type Janitor
- type Pool
Constants ¶
const ( NoExpirationCheck time.Duration = -1 // For use with functions that take an expiration time. NoExpiration time.Duration = -1 // For use with functions that take an expiration time. Equivalent to // passing in the same expiration duration as was given to NewCache() or // NewCacheFrom() 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 Cache ¶
type Cache[K comparable, T any] struct { // contains filtered or unexported fields }
func NewCache ¶
func NewCache[K comparable, T any](defaultExpiration, errorAllowTimeExpiration time.Duration) *Cache[K, T]
Return a new cache with a given default expiration duration (defaultExpiration) and cleanup interval. If the expiration duration is less than one (or NoExpiration), the items in the cache never expire (by default), and must be deleted manually. If the cleanup errorAllowTimeExpiration is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().
func NewCacheFrom ¶
func NewCacheFrom[K comparable, T any](defaultExpiration, errorAllowTimeExpiration time.Duration, items map[K]Item[T]) *Cache[K, T]
Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than one (or NoExpiration), the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().
NewFrom() also accepts an items map which will serve as the underlying map for the cache. This is useful for starting from a deserialized cache (serialized using e.g. gob.Encode() on c.Items()), or passing in e.g. make(map[string]Item, 500) to improve startup performance when the cache is expected to reach a certain minimum size.
Only the cache's methods synchronize access to this map, so it is not recommended to keep any references to the map around after creating a cache. If need be, the map can be accessed at a later point using c.Items() (subject to the same caveat.)
Note regarding serialization: When using e.g. gob, make sure to gob.Register() the individual types stored in the cache before encoding a map retrieved with c.Items(), and to register those same types before decoding a blob containing an items map.
func (Cache) 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 (Cache) Decrement ¶
Decrement and return an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64, float32 or float64 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.
func (Cache) Delete ¶
func (c Cache) Delete(k K)
Delete an item from the cache. Does nothing if the key is not in the cache.
func (Cache) DeleteExpired ¶
func (c Cache) DeleteExpired()
Delete all expired items from the cache.
func (Cache) DeleteRegex ¶
func (c Cache) DeleteRegex(rule string)
func (Cache) Get ¶
func (c Cache) Get(k K) (T, bool)
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Cache) GetMultipleItems ¶
func (c Cache) GetMultipleItems(keys []K) []T
GetMultipleItems returns an array of items corresponding to the input array
func (Cache) GetOrCreateNew ¶
func (c Cache) GetOrCreateNew(k K) (T, bool)
func (Cache) GetRandom ¶
func (c Cache) GetRandom() (key K, val T, b bool)
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Cache) GetRandomThenDelete ¶
func (c Cache) GetRandomThenDelete() (key K, val T, b bool)
func (Cache) GetThenDelete ¶
func (c Cache) GetThenDelete(k K) (T, bool)
func (Cache) GetWithDefaultExpirationUpdate ¶
func (c Cache) GetWithDefaultExpirationUpdate(k K) (T, bool)
func (Cache) 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 (Cache) GetWithExpirationUpdate ¶
GetWithExpirationUpdate returns item and updates its cache expiration time 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 (Cache) Increment ¶
Increment and return an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64, float32 or float64 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.
func (Cache) IncrementExpiration ¶
func (Cache) ItemCount ¶
func (c Cache) 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 (Cache) Items ¶
func (c Cache) Items() map[K]Item[T]
Copies all unexpired items in the cache into a new map and returns it.
func (Cache) Iterate ¶
Iterate every item by item handle items from cache,and if the handle returns to false, it will be interrupted and return false.
func (Cache) Keys ¶
func (c Cache) Keys() []K
Keys returns a sorted slice of all the keys in the cache.
func (Cache) 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 (Cache) 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 (Cache) OnEvicted ¶
func (c Cache) OnEvicted(f func(K, T))
Sets an (optional) function that is called with the key and value when an item is evicted from the cache. (Including when it is deleted manually, but not when it is overwritten.) Set to nil to disable.
func (Cache) 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 (Cache) 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 (Cache) 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 (Cache) 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 (Cache) SetDefault ¶
func (c Cache) SetDefault(k K, x T)
Add an item to the cache, replacing any existing item, using the default expiration.
func (*Cache[K, T]) SetNextCheckExpireate ¶
type CacheFiles ¶
func NewCacheFiles ¶
func NewCacheFiles(rootDir string, defaultExpiration, errorAllowTimeExpiration time.Duration) *CacheFiles
func (CacheFiles) 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 (CacheFiles) Decrement ¶
Decrement and return an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64, float32 or float64 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.
func (CacheFiles) Delete ¶
func (c CacheFiles) Delete(k K)
Delete an item from the cache. Does nothing if the key is not in the cache.
func (CacheFiles) DeleteExpired ¶
func (c CacheFiles) DeleteExpired()
Delete all expired items from the cache.
func (CacheFiles) DeleteRegex ¶
func (c CacheFiles) DeleteRegex(rule string)
func (CacheFiles) Get ¶
func (c CacheFiles) Get(k K) (T, bool)
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (*CacheFiles) GetCacheFile ¶
func (cf *CacheFiles) GetCacheFile(fname string) (string, bool)
func (*CacheFiles) GetCacheFileContent ¶
func (cf *CacheFiles) GetCacheFileContent(fname string) (content []byte, err error)
func (*CacheFiles) GetCacheFileContentString ¶
func (cf *CacheFiles) GetCacheFileContentString(fname string) (string, error)
func (*CacheFiles) GetCacheFileOrCreate ¶
func (cf *CacheFiles) GetCacheFileOrCreate(fname string) (pathCacheFile string, isOldFile bool)
func (*CacheFiles) GetCacheFileOrCreateWithExpiration ¶
func (*CacheFiles) GetCacheFromUrl ¶
func (cf *CacheFiles) GetCacheFromUrl(fname, url, user, password string) (pathCacheFile string, err error)
func (CacheFiles) GetMultipleItems ¶
func (c CacheFiles) GetMultipleItems(keys []K) []T
GetMultipleItems returns an array of items corresponding to the input array
func (CacheFiles) GetOrCreateNew ¶
func (c CacheFiles) GetOrCreateNew(k K) (T, bool)
func (CacheFiles) GetRandom ¶
func (c CacheFiles) GetRandom() (key K, val T, b bool)
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (CacheFiles) GetRandomThenDelete ¶
func (c CacheFiles) GetRandomThenDelete() (key K, val T, b bool)
func (CacheFiles) GetThenDelete ¶
func (c CacheFiles) GetThenDelete(k K) (T, bool)
func (CacheFiles) GetWithDefaultExpirationUpdate ¶
func (c CacheFiles) GetWithDefaultExpirationUpdate(k K) (T, bool)
func (CacheFiles) 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 (CacheFiles) GetWithExpirationUpdate ¶
GetWithExpirationUpdate returns item and updates its cache expiration time 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 (CacheFiles) Increment ¶
Increment and return an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64, float32 or float64 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.
func (CacheFiles) IncrementExpiration ¶
func (CacheFiles) ItemCount ¶
func (c CacheFiles) 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 (CacheFiles) Items ¶
func (c CacheFiles) Items() map[K]Item[T]
Copies all unexpired items in the cache into a new map and returns it.
func (CacheFiles) Iterate ¶
Iterate every item by item handle items from cache,and if the handle returns to false, it will be interrupted and return false.
func (CacheFiles) Keys ¶
func (c CacheFiles) Keys() []K
Keys returns a sorted slice of all the keys in the cache.
func (CacheFiles) 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 (CacheFiles) 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 (CacheFiles) OnEvicted ¶
func (c CacheFiles) OnEvicted(f func(K, T))
Sets an (optional) function that is called with the key and value when an item is evicted from the cache. (Including when it is deleted manually, but not when it is overwritten.) Set to nil to disable.
func (CacheFiles) 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 (CacheFiles) 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 (CacheFiles) 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 (CacheFiles) 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 (CacheFiles) SetDefault ¶
func (c CacheFiles) SetDefault(k K, x T)
Add an item to the cache, replacing any existing item, using the default expiration.
type CacheFuncs ¶
func NewCacheFuncs ¶
func NewCacheFuncs(defaultExpiration, errorAllowTimeExpiration time.Duration) *CacheFuncs
func (CacheFuncs) 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 (*CacheFuncs) AddFuncIfNotExist ¶
func (*CacheFuncs) CallFunc ¶
func (cf *CacheFuncs) CallFunc(fname string) (results []interface{}, err error)
func (CacheFuncs) Decrement ¶
Decrement and return an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64, float32 or float64 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.
func (CacheFuncs) Delete ¶
func (c CacheFuncs) Delete(k K)
Delete an item from the cache. Does nothing if the key is not in the cache.
func (CacheFuncs) DeleteExpired ¶
func (c CacheFuncs) DeleteExpired()
Delete all expired items from the cache.
func (CacheFuncs) DeleteRegex ¶
func (c CacheFuncs) DeleteRegex(rule string)
func (CacheFuncs) Get ¶
func (c CacheFuncs) Get(k K) (T, bool)
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (CacheFuncs) GetMultipleItems ¶
func (c CacheFuncs) GetMultipleItems(keys []K) []T
GetMultipleItems returns an array of items corresponding to the input array
func (CacheFuncs) GetOrCreateNew ¶
func (c CacheFuncs) GetOrCreateNew(k K) (T, bool)
func (CacheFuncs) GetRandom ¶
func (c CacheFuncs) GetRandom() (key K, val T, b bool)
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (CacheFuncs) GetRandomThenDelete ¶
func (c CacheFuncs) GetRandomThenDelete() (key K, val T, b bool)
func (CacheFuncs) GetThenDelete ¶
func (c CacheFuncs) GetThenDelete(k K) (T, bool)
func (CacheFuncs) GetWithDefaultExpirationUpdate ¶
func (c CacheFuncs) GetWithDefaultExpirationUpdate(k K) (T, bool)
func (CacheFuncs) 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 (CacheFuncs) GetWithExpirationUpdate ¶
GetWithExpirationUpdate returns item and updates its cache expiration time 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 (CacheFuncs) Increment ¶
Increment and return an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64, float32 or float64 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.
func (CacheFuncs) IncrementExpiration ¶
func (CacheFuncs) ItemCount ¶
func (c CacheFuncs) 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 (CacheFuncs) Items ¶
func (c CacheFuncs) Items() map[K]Item[T]
Copies all unexpired items in the cache into a new map and returns it.
func (CacheFuncs) Iterate ¶
Iterate every item by item handle items from cache,and if the handle returns to false, it will be interrupted and return false.
func (CacheFuncs) Keys ¶
func (c CacheFuncs) Keys() []K
Keys returns a sorted slice of all the keys in the cache.
func (CacheFuncs) 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 (CacheFuncs) 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 (CacheFuncs) OnEvicted ¶
func (c CacheFuncs) OnEvicted(f func(K, T))
Sets an (optional) function that is called with the key and value when an item is evicted from the cache. (Including when it is deleted manually, but not when it is overwritten.) Set to nil to disable.
func (CacheFuncs) 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 (CacheFuncs) 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 (CacheFuncs) 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 (CacheFuncs) 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 (CacheFuncs) SetDefault ¶
func (c CacheFuncs) SetDefault(k K, x T)
Add an item to the cache, replacing any existing item, using the default expiration.
type CachePools ¶
type CachePools[K constraints.Ordered, T any] struct { // contains filtered or unexported fields }
func NewCachePools ¶
func NewCachePools[K constraints.Ordered, T any](defaultExpiration, errorAllowTimeExpiration time.Duration, numpools int) *CachePools[K, T]
func (*CachePools[K, T]) Decrement ¶
func (sc *CachePools[K, T]) Decrement(k K, n int64) error
func (*CachePools[K, T]) Delete ¶
func (sc *CachePools[K, T]) Delete(k K)
func (*CachePools[K, T]) DeleteExpired ¶
func (sc *CachePools[K, T]) DeleteExpired()
func (*CachePools[K, T]) Edit ¶
func (sc *CachePools[K, T]) Edit(k K, x interface{}, apFunc func(T, interface{}) (T, error)) error
func (*CachePools[K, T]) Flush ¶
func (sc *CachePools[K, T]) Flush()
func (*CachePools[K, T]) Get ¶
func (sc *CachePools[K, T]) Get(k K) (T, bool)
func (*CachePools[K, T]) GetWithDefaultExpirationUpdate ¶
func (sc *CachePools[K, T]) GetWithDefaultExpirationUpdate(k K) (T, bool)
func (*CachePools[K, T]) GetWithExpirationGet ¶
func (sc *CachePools[K, T]) GetWithExpirationGet(k K) (T, time.Time, bool)
func (*CachePools[K, T]) GetWithExpirationUpdate ¶
func (sc *CachePools[K, T]) GetWithExpirationUpdate(k K, d time.Duration) (T, bool)
func (*CachePools[K, T]) Increment ¶
func (sc *CachePools[K, T]) Increment(k K, n int64) error
func (*CachePools[K, T]) Items ¶
func (sc *CachePools[K, T]) Items() []map[K]Item[T]
Returns the items in the cache. This may include items that have expired, but have not yet been cleaned up. If this is significant, the Expiration fields of the items should be checked. Note that explicit synchronization is needed to use a cache and its corresponding Items() return values at the same time, as the maps are shared.
func (*CachePools[K, T]) Keys ¶
func (sc *CachePools[K, T]) Keys() (keys []K)
func (*CachePools[K, T]) LoadFile ¶
func (sc *CachePools[K, T]) LoadFile(fname string) error
Load and add cache items from the given filename, excluding any items with keys that already exist in the current cache.
func (*CachePools[K, T]) Replace ¶
func (sc *CachePools[K, T]) Replace(k K, x T, d time.Duration) error
func (*CachePools[K, T]) SaveFile ¶
func (sc *CachePools[K, T]) SaveFile(fname string) error
func (*CachePools[K, T]) Set ¶
func (sc *CachePools[K, T]) Set(k K, x T, d time.Duration)
func (*CachePools[K, T]) SetDefault ¶
func (sc *CachePools[K, T]) SetDefault(k K, x T)
type Janitor ¶
func NewJanitor ¶
func (*Janitor) GetInterval ¶
func (*Janitor) ResetDefault ¶
func (j *Janitor) ResetDefault()