Documentation
¶
Index ¶
- Variables
- type Cache
- func (c *Cache) Decrement(k string, n int64) (int64, error)
- func (c *Cache) Delete(k string) (int64, error)
- func (c *Cache) DeleteExpired()
- func (c *Cache) Flush()
- func (c *Cache) Get(k string) interface{}
- func (c *Cache) GetLock(key string, acquireTimeout, lockTimeOut time.Duration) (string, error)
- func (c *Cache) GetString(k string) (string, error)
- func (c *Cache) Increment(k string, n int64) (int64, error)
- func (c *Cache) IncrementFloat(k string, n float64) (float64, error)
- func (c *Cache) IsExist(k string) bool
- func (c *Cache) LPush(key string, value interface{}) (int64, error)
- func (c *Cache) Load(r io.Reader) error
- func (c *Cache) LoadFile(fname string) error
- func (c *Cache) RPop(key string) interface{}
- func (c *Cache) ReleaseLock(key string, value string) bool
- func (c *Cache) Save(w io.Writer) (err error)
- func (c *Cache) SaveFile(fname string) error
- func (c *Cache) Set(key string, value interface{}, timeout time.Duration) error
- func (c *Cache) WithContext(ctx context.Context) icache.ICache
- func (c *Cache) WithDB(db int) icache.ICache
- func (c *Cache) XAdd(key, id string, values []string) (string, error)
- func (c *Cache) XDel(key string, value string) (int64, error)
- func (c *Cache) XRead(key string, value int64) (interface{}, error)
- func (c *Cache) ZAdd(s string, f float64, i interface{}) interface{}
- func (c *Cache) ZRangeByScore(s string, i int64, i2 int64) ([]string, error)
- func (c *Cache) ZRem(s string, i ...interface{}) error
- type Option
- type ShardedCache
- func (sc *ShardedCache) Decrement(key string, val int64) (int64, error)
- func (sc *ShardedCache) Delete(key string) (int64, error)
- func (sc *ShardedCache) DeleteExpired()
- func (sc *ShardedCache) Flush()
- func (sc *ShardedCache) Get(key string) interface{}
- func (sc *ShardedCache) GetLock(lockName string, acquireTimeout, lockTimeOut time.Duration) (string, error)
- func (sc *ShardedCache) GetString(key string) (string, error)
- func (sc *ShardedCache) Increment(key string, val int64) (int64, error)
- func (sc *ShardedCache) IncrementFloat(key string, val float64) (float64, error)
- func (sc *ShardedCache) IsExist(key string) bool
- func (sc *ShardedCache) LPush(key string, val interface{}) (int64, error)
- func (sc *ShardedCache) RPop(key string) interface{}
- func (sc *ShardedCache) ReleaseLock(key string, val string) bool
- func (sc *ShardedCache) Set(key string, val interface{}, timeout time.Duration) error
- func (sc *ShardedCache) WithContext(ctx context.Context) icache.ICache
- func (sc *ShardedCache) WithDB(db int) icache.ICache
- func (sc *ShardedCache) XAdd(key, id string, values []string) (string, error)
- func (sc *ShardedCache) XDel(key string, val string) (int64, error)
- func (sc *ShardedCache) XRead(key string, val int64) (interface{}, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyExists = fmt.Errorf("item already exists") ErrCacheMiss = fmt.Errorf("item not found") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
func New ¶
Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than 1, 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 their next lookup or before calling DeleteExpired.
func (*Cache) Decrement ¶
Decrement an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or int64 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. Stops at 0 on underflow.
func (*Cache) DeleteExpired ¶
func (c *Cache) DeleteExpired()
Delete all expired items from the cache.
func (*Cache) Get ¶
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (*Cache) GetString ¶
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (*Cache) Increment ¶
Increment an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or int64 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. Wraps around on overlow.
func (*Cache) 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.
func (*Cache) Load ¶
Add (Gob-serialized) cache items from an io.Reader, excluding any items with keys that already exist in the current cache.
func (*Cache) LoadFile ¶
Load and add cache items from the given filename, excluding any items with keys that already exist in the current cache.
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.
func (*Cache) Set ¶
Add an item to the cache, replacing any existing item. If the duration is 0, the cache's default expiration time is used. If it is -1, the item never expires.
func (*Cache) ZRangeByScore ¶ added in v0.2.12
type Option ¶
type Option func(p *config)
func WithAttributes ¶
WithAttributes specifies additional attributes to be added to the span.
func WithCleanupInterval ¶
func WithDefaultExpiration ¶
func WithTracer ¶
WithTracer specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.
type ShardedCache ¶
type ShardedCache struct {
// contains filtered or unexported fields
}
func (*ShardedCache) Decrement ¶
func (sc *ShardedCache) Decrement(key string, val int64) (int64, error)
func (*ShardedCache) DeleteExpired ¶
func (sc *ShardedCache) DeleteExpired()
func (*ShardedCache) Flush ¶
func (sc *ShardedCache) Flush()
func (*ShardedCache) Get ¶
func (sc *ShardedCache) Get(key string) interface{}
func (*ShardedCache) Increment ¶
func (sc *ShardedCache) Increment(key string, val int64) (int64, error)
func (*ShardedCache) IncrementFloat ¶
func (sc *ShardedCache) IncrementFloat(key string, val float64) (float64, error)
func (*ShardedCache) IsExist ¶
func (sc *ShardedCache) IsExist(key string) bool
func (*ShardedCache) LPush ¶
func (sc *ShardedCache) LPush(key string, val interface{}) (int64, error)
func (*ShardedCache) RPop ¶
func (sc *ShardedCache) RPop(key string) interface{}
func (*ShardedCache) ReleaseLock ¶
func (sc *ShardedCache) ReleaseLock(key string, val string) bool
func (*ShardedCache) Set ¶
func (sc *ShardedCache) Set(key string, val interface{}, timeout time.Duration) error
func (*ShardedCache) WithContext ¶
func (sc *ShardedCache) WithContext(ctx context.Context) icache.ICache