Documentation
¶
Index ¶
- Constants
- Variables
- type ARC
- func (c *ARC) Flush()
- func (c *ARC) Get(key any) (any, error)
- func (c *ARC) GetALL(checkExpired bool) map[any]any
- func (c *ARC) GetIFPresent(key any) (any, error)
- func (c *ARC) Has(key any) bool
- func (c *ARC) Keys(checkExpired bool) []any
- func (c *ARC) Len(checkExpired bool) int
- func (c *ARC) Purge()
- func (c *ARC) Remove(key any) bool
- func (c *ARC) Set(key, value any, expiration time.Duration) error
- func (c *ARC) SetNX(k any, x any, d time.Duration) error
- type AddedFunc
- type Cache
- type CacheBuilder
- func (cb *CacheBuilder) ARC() *CacheBuilder
- func (cb *CacheBuilder) AddedFunc(addedFunc AddedFunc) *CacheBuilder
- func (cb *CacheBuilder) Build() Cache
- func (cb *CacheBuilder) EvictType(tp string) *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() *CacheBuilder
- func (cb *CacheBuilder) LRU() *CacheBuilder
- func (cb *CacheBuilder) LoaderFunc(loaderFunc LoaderFunc) *CacheBuilder
- func (cb *CacheBuilder) PurgeVisitorFunc(purgeVisitorFunc PurgeVisitorFunc) *CacheBuilder
- func (cb *CacheBuilder) Simple() *CacheBuilder
- type DeserializeFunc
- type EvictedFunc
- type Group
- type LFU
- func (c *LFU) Flush()
- func (c *LFU) Get(key any) (any, error)
- func (c *LFU) GetALL(checkExpired bool) map[any]any
- func (c *LFU) GetIFPresent(key any) (any, error)
- func (c *LFU) Has(key any) bool
- func (c *LFU) Keys(checkExpired bool) []any
- func (c *LFU) Len(checkExpired bool) int
- func (c *LFU) Purge()
- func (c *LFU) Remove(key any) bool
- func (c *LFU) Set(key, value any, expiration time.Duration) error
- func (c *LFU) SetNX(k any, x any, d time.Duration) error
- type LRU
- func (c *LRU) Flush()
- func (c *LRU) Get(key any) (any, error)
- func (c *LRU) GetALL(checkExpired bool) map[any]any
- func (c *LRU) GetIFPresent(key any) (any, error)
- func (c *LRU) Has(key any) bool
- func (c *LRU) Keys(checkExpired bool) []any
- func (c *LRU) Len(checkExpired bool) int
- func (c *LRU) Purge()
- func (c *LRU) Remove(key any) bool
- func (c *LRU) Set(key, value any, expiration time.Duration) error
- func (c *LRU) SetNX(k any, x any, d time.Duration) error
- type LoaderFunc
- type PurgeVisitorFunc
- type SerializeFunc
- type Simple
- func (c *Simple) Decrement(k any, n int64) error
- func (c *Simple) DecrementFloat(k any, n float64) error
- func (c *Simple) DecrementFloat32(k any, n float32) (float32, error)
- func (c *Simple) DecrementFloat64(k any, n float64) (float64, error)
- func (c *Simple) DecrementInt(k any, n int) (int, error)
- func (c *Simple) DecrementInt32(k any, n int32) (int32, error)
- func (c *Simple) DecrementInt64(k any, n int64) (int64, error)
- func (c *Simple) DecrementUint(k any, n uint) (uint, error)
- func (c *Simple) DecrementUint32(k any, n uint32) (uint32, error)
- func (c *Simple) DecrementUint64(k any, n uint64) (uint64, error)
- func (c *Simple) DecrementUintptr(k any, n uintptr) (uintptr, error)
- func (c *Simple) Flush()
- func (c *Simple) Get(k any) (any, error)
- func (c *Simple) GetALL(checkExpired bool) map[any]any
- func (c *Simple) GetWithExpiration(k any) (any, time.Time, error)
- func (c *Simple) Has(key any) bool
- func (c *Simple) Increment(k any, n int64) error
- func (c *Simple) IncrementFloat(k any, n float64) error
- func (c *Simple) IncrementFloat32(k any, n float32) (float32, error)
- func (c *Simple) IncrementFloat64(k any, n float64) (float64, error)
- func (c *Simple) IncrementInt(k any, n int) (int, error)
- func (c *Simple) IncrementInt32(k any, n int32) (int32, error)
- func (c *Simple) IncrementInt64(k any, n int64) (int64, error)
- func (c *Simple) IncrementUint(k any, n uint) (uint, error)
- func (c *Simple) IncrementUint32(k any, n uint32) (uint32, error)
- func (c *Simple) IncrementUint64(k any, n uint64) (uint64, error)
- func (c *Simple) IncrementUintptr(k any, n uintptr) (uintptr, error)
- func (c *Simple) Items() map[any]item
- func (c *Simple) Keys(checkExpired bool) []any
- func (c *Simple) Len(checkExpired bool) int
- func (c *Simple) Load(r io.Reader) error
- func (c *Simple) LoadFile(fname string) error
- func (c *Simple) OnEvicted(f func(any, any))
- func (c *Simple) Purge()
- func (c *Simple) Remove(k any) bool
- func (c *Simple) Replace(k any, x any, d time.Duration) error
- func (c *Simple) Save(w io.Writer) (err error)
- func (c *Simple) SaveFile(fname string) error
- func (c *Simple) Set(k any, x any, d time.Duration) error
- func (c *Simple) SetNX(k any, x any, d time.Duration) error
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.
func (*ARC) 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 (*ARC) GetIFPresent ¶
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.
type Cache ¶
type Cache interface {
Set(key, value any, expiration time.Duration) error
SetNX(key, value any, expiration time.Duration) error
Get(key any) (any, error)
GetALL(checkExpired bool) map[any]any
Remove(key any) bool
Keys(checkExpired bool) []any
Len(checkExpired bool) int
Has(key any) bool
Purge()
Flush()
// contains filtered or unexported methods
}
type CacheBuilder ¶
type CacheBuilder struct {
// contains filtered or unexported fields
}
func New ¶
func New(size int) *CacheBuilder
func (*CacheBuilder) ARC ¶
func (cb *CacheBuilder) ARC() *CacheBuilder
func (*CacheBuilder) AddedFunc ¶
func (cb *CacheBuilder) AddedFunc(addedFunc AddedFunc) *CacheBuilder
func (*CacheBuilder) Build ¶
func (cb *CacheBuilder) Build() Cache
func (*CacheBuilder) EvictType ¶
func (cb *CacheBuilder) EvictType(tp string) *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() *CacheBuilder
func (*CacheBuilder) LRU ¶
func (cb *CacheBuilder) LRU() *CacheBuilder
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) PurgeVisitorFunc ¶
func (cb *CacheBuilder) PurgeVisitorFunc(purgeVisitorFunc PurgeVisitorFunc) *CacheBuilder
func (*CacheBuilder) Simple ¶
func (cb *CacheBuilder) Simple() *CacheBuilder
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.
func (*LFU) Get ¶
Get a value from cache pool using key if it exists. If it dose not exists key and has LoaderFunc, generate a value using `LoaderFunc` method returns value.
func (*LFU) GetIFPresent ¶
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.
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
Discards the least recently used items first.
func (*LRU) Get ¶
Get a value from cache pool using key if it exists. If it dose not exists key and has LoaderFunc, generate a value using `LoaderFunc` method returns value.
func (*LRU) GetIFPresent ¶
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.
type PurgeVisitorFunc ¶
type Simple ¶
type Simple struct {
// contains filtered or unexported fields
}
func (*Simple) Decrement ¶
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 (*Simple) DecrementFloat ¶
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 (*Simple) DecrementFloat32 ¶
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 (*Simple) DecrementFloat64 ¶
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 (*Simple) DecrementInt ¶
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 (*Simple) DecrementInt32 ¶
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 (*Simple) DecrementInt64 ¶
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 (*Simple) DecrementUint ¶
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 (*Simple) DecrementUint32 ¶
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 (*Simple) DecrementUint64 ¶
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 (*Simple) DecrementUintptr ¶
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 (*Simple) Get ¶
Get an item from the Simple. Returns the item or nil, and a bool indicating whether the key was found.
func (*Simple) GetWithExpiration ¶
GetWithExpiration returns an item and its expiration time from the Simple. 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 (*Simple) Increment ¶
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 (*Simple) IncrementFloat ¶
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 (*Simple) IncrementFloat32 ¶
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 (*Simple) IncrementFloat64 ¶
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 (*Simple) IncrementInt ¶
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 (*Simple) IncrementInt32 ¶
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 (*Simple) IncrementInt64 ¶
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 (*Simple) IncrementUint ¶
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 (*Simple) IncrementUint32 ¶
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 (*Simple) IncrementUint64 ¶
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 (*Simple) IncrementUintptr ¶
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.
func (*Simple) Load ¶
SetNX (Gob-serialized) Simple items from an io.Reader, excluding any items with keys that already exist (and haven't expired) in the current Simple.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (*Simple) LoadFile ¶
Load and add Simple items from the given filename, excluding any items with keys that already exist in the current Simple.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (*Simple) OnEvicted ¶
Sets an (optional) function that is called with the key and value when an item is evicted from the Simple. (Including when it is deleted manually, but not when it is overwritten.) Set to nil to disable.
func (*Simple) Remove ¶
Remove an item from the Simple. Does nothing if the key is not in the Simple.
func (*Simple) Replace ¶
Set a new value for the Simple key only if it already exists, and the existing item hasn't expired. Returns an error otherwise.
func (*Simple) Save ¶
Write the Simple'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 (*Simple) SaveFile ¶
Save the Simple'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().)
