Documentation
¶
Index ¶
- Constants
- Variables
- type ARC
- type AddedFunc
- type Cache
- func (c *Cache) Clear()
- func (c *Cache) Decrement(k any, n int64) error
- func (c *Cache) DecrementFloat(k any, n float64) error
- func (c *Cache) DecrementFloat32(k any, n float32) (float32, error)
- func (c *Cache) DecrementFloat64(k any, n float64) (float64, error)
- func (c *Cache) DecrementInt(k any, n int) (int, error)
- func (c *Cache) DecrementInt32(k any, n int32) (int32, error)
- func (c *Cache) DecrementInt64(k any, n int64) (int64, error)
- func (c *Cache) DecrementUint(k any, n uint) (uint, error)
- func (c *Cache) DecrementUint32(k any, n uint32) (uint32, error)
- func (c *Cache) DecrementUint64(k any, n uint64) (uint64, error)
- func (c *Cache) DecrementUintptr(k any, n uintptr) (uintptr, error)
- func (c *Cache) Get(key any) (any, error)
- func (c *Cache) GetALL(checkExpired bool) map[any]any
- func (c *Cache) GetIFPresent(key any) (any, error)
- func (c *Cache) GetWithExpiration(key any) (any, time.Duration, error)
- func (c *Cache) Has(key any) bool
- func (c *Cache) Increment(k any, n int64) error
- func (c *Cache) IncrementFloat(k any, n float64) error
- func (c *Cache) IncrementFloat32(k any, n float32) (float32, error)
- func (c *Cache) IncrementFloat64(k any, n float64) (float64, error)
- func (c *Cache) IncrementInt(k any, n int) (int, error)
- func (c *Cache) IncrementInt32(k any, n int32) (int32, error)
- func (c *Cache) IncrementInt64(k any, n int64) (int64, error)
- func (c *Cache) IncrementUint(k any, n uint) (uint, error)
- func (c *Cache) IncrementUint32(k any, n uint32) (uint32, error)
- func (c *Cache) IncrementUint64(k any, n uint64) (uint64, error)
- func (c *Cache) IncrementUintptr(k any, n uintptr) (uintptr, error)
- func (c *Cache) Keys(checkExpired bool) []any
- func (c *Cache) Len(checkExpired bool) int
- func (c *Cache) Purge()
- func (c *Cache) Remove(key any) bool
- func (c *Cache) Set(key, value any, expiration time.Duration) error
- func (c *Cache) SetNX(k any, x any, expiration time.Duration) error
- type CacheBuilder
- func (cb *CacheBuilder) ARC() *Cache
- func (cb *CacheBuilder) AddedFunc(addedFunc AddedFunc) *CacheBuilder
- func (cb *CacheBuilder) ClearVisitorFunc(purgeVisitorFunc ClearVisitorFunc) *CacheBuilder
- func (cb *CacheBuilder) EvictedFunc(evictedFunc EvictedFunc) *CacheBuilder
- func (cb *CacheBuilder) Expiration(expiration time.Duration) *CacheBuilder
- func (cb *CacheBuilder) Janitor(interval time.Duration) *CacheBuilder
- func (cb *CacheBuilder) LFU() *Cache
- func (cb *CacheBuilder) LRU() *Cache
- func (cb *CacheBuilder) LoaderFunc(loaderFunc LoaderFunc) *CacheBuilder
- func (cb *CacheBuilder) Simple() *Cache
- type ClearVisitorFunc
- type DeserializeFunc
- type EvictedFunc
- type Group
- type LFU
- type LRU
- type LoaderFunc
- type SerializeFunc
- type Simple
- type Store
Constants ¶
const ( TYPE_LRU = "lru" TYPE_LFU = "lfu" TYPE_ARC = "arc" TYPE_Simple = "simple" )
const ( // 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 New() or // NewFrom() when the Simple was created (e.g. 5 minutes.) DefaultExpiration time.Duration = 0 )
Variables ¶
var ( KeyNotFoundError = errors.New("key not found") KeyAlreadyExistError = errors.New("key already exist") )
Functions ¶
This section is empty.
Types ¶
type ARC ¶
type ARC struct {
// contains filtered or unexported fields
}
Constantly balances between LRU and LFU, to improve the combined result.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func (*Cache) Clear ¶ added in v1.7.8
func (c *Cache) Clear()
Clear is used to completely clear the cache
func (*Cache) Decrement ¶ added in v1.7.8
Decrement 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. To retrieve the decremented value, use one of the specialized methods, e.g. DecrementInt64.
func (*Cache) DecrementFloat ¶ added in v1.7.8
Decrement an item of type float32 or float64 by n. Returns an error if the item's value is not floating point, if it was not found, or if it is not possible to decrement it by n. Pass a negative number to decrement the value. To retrieve the decremented value, use one of the specialized methods, e.g. DecrementFloat64.
func (*Cache) DecrementFloat32 ¶ added in v1.7.8
Decrement an item of type float32 by n. Returns an error if the item's value is not an float32, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementFloat64 ¶ added in v1.7.8
Decrement an item of type float64 by n. Returns an error if the item's value is not an float64, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementInt ¶ added in v1.7.8
Decrement an item of type int by n. Returns an error if the item's value is not an int, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementInt32 ¶ added in v1.7.8
Decrement an item of type int32 by n. Returns an error if the item's value is not an int32, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementInt64 ¶ added in v1.7.8
Decrement an item of type int64 by n. Returns an error if the item's value is not an int64, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUint ¶ added in v1.7.8
Decrement an item of type uint by n. Returns an error if the item's value is not an uint, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUint32 ¶ added in v1.7.8
Decrement an item of type uint32 by n. Returns an error if the item's value is not an uint32, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUint64 ¶ added in v1.7.8
Decrement an item of type uint64 by n. Returns an error if the item's value is not an uint64, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUintptr ¶ added in v1.7.8
Decrement an item of type uintptr by n. Returns an error if the item's value is not an uintptr, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) Get ¶
Get a value from cache pool using key if it exists. If not exists and it has LoaderFunc, it will generate the value using you have specified LoaderFunc method returns value.
func (*Cache) GetIFPresent ¶ added in v1.7.8
GetIFPresent gets a value from cache pool using key if it exists. If it dose not exists key, returns KeyNotFoundError. And send a request which refresh value for specified key if cache object has LoaderFunc.
func (*Cache) GetWithExpiration ¶ added in v1.7.8
func (*Cache) Increment ¶ added in v1.7.8
Increment 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. To retrieve the incremented value, use one of the specialized methods, e.g. IncrementInt64.
func (*Cache) IncrementFloat ¶ added in v1.7.8
Increment an item of type float32 or float64 by n. Returns an error if the item's value is not floating point, if it was not found, or if it is not possible to increment it by n. Pass a negative number to decrement the value. To retrieve the incremented value, use one of the specialized methods, e.g. IncrementFloat64.
func (*Cache) IncrementFloat32 ¶ added in v1.7.8
Increment an item of type float32 by n. Returns an error if the item's value is not an float32, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementFloat64 ¶ added in v1.7.8
Increment an item of type float64 by n. Returns an error if the item's value is not an float64, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementInt ¶ added in v1.7.8
Increment an item of type int by n. Returns an error if the item's value is not an int, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementInt32 ¶ added in v1.7.8
Increment an item of type int32 by n. Returns an error if the item's value is not an int32, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementInt64 ¶ added in v1.7.8
Increment an item of type int64 by n. Returns an error if the item's value is not an int64, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUint ¶ added in v1.7.8
Increment an item of type uint by n. Returns an error if the item's value is not an uint, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUint32 ¶ added in v1.7.8
Increment an item of type uint32 by n. Returns an error if the item's value is not an uint32, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUint64 ¶ added in v1.7.8
Increment an item of type uint64 by n. Returns an error if the item's value is not an uint64, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUintptr ¶ added in v1.7.8
Increment an item of type uintptr by n. Returns an error if the item's value is not an uintptr, or if it was not found. If there is no error, the incremented value is returned.
type CacheBuilder ¶
type CacheBuilder struct {
// contains filtered or unexported fields
}
func New ¶
func New(size int) *CacheBuilder
func (*CacheBuilder) ARC ¶
func (cb *CacheBuilder) ARC() *Cache
func (*CacheBuilder) AddedFunc ¶
func (cb *CacheBuilder) AddedFunc(addedFunc AddedFunc) *CacheBuilder
func (*CacheBuilder) ClearVisitorFunc ¶ added in v1.7.8
func (cb *CacheBuilder) ClearVisitorFunc(purgeVisitorFunc ClearVisitorFunc) *CacheBuilder
func (*CacheBuilder) EvictedFunc ¶
func (cb *CacheBuilder) EvictedFunc(evictedFunc EvictedFunc) *CacheBuilder
func (*CacheBuilder) Expiration ¶
func (cb *CacheBuilder) Expiration(expiration time.Duration) *CacheBuilder
func (*CacheBuilder) Janitor ¶
func (cb *CacheBuilder) Janitor(interval time.Duration) *CacheBuilder
func (*CacheBuilder) LFU ¶
func (cb *CacheBuilder) LFU() *Cache
func (*CacheBuilder) LRU ¶
func (cb *CacheBuilder) LRU() *Cache
func (*CacheBuilder) LoaderFunc ¶
func (cb *CacheBuilder) LoaderFunc(loaderFunc LoaderFunc) *CacheBuilder
Set a loader function with expiration. loaderFunc: create a new value with this function if cached value is expired. If nil returned instead of time.Duration from loaderFunc than value will never expire.
func (*CacheBuilder) Simple ¶
func (cb *CacheBuilder) Simple() *Cache
type ClearVisitorFunc ¶ added in v1.7.8
type EvictedFunc ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.
type LFU ¶
type LFU struct {
// contains filtered or unexported fields
}
Discards the least frequently used items first.
