memory

package
v0.2.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyExists = fmt.Errorf("item already exists")
	ErrCacheMiss = fmt.Errorf("item not found")
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Cache

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

func (c *Cache) Decrement(k string, n int64) (int64, error)

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) Delete

func (c *Cache) Delete(k string) (int64, error)

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) Flush

func (c *Cache) Flush()

Delete all items from the cache.

func (*Cache) Get

func (c *Cache) Get(k string) interface{}

Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.

func (*Cache) GetLock

func (c *Cache) GetLock(key string, acquireTimeout, lockTimeOut time.Duration) (string, error)

func (*Cache) GetString

func (c *Cache) GetString(k string) (string, error)

Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.

func (*Cache) Increment

func (c *Cache) Increment(k string, n int64) (int64, error)

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

func (c *Cache) IncrementFloat(k string, n float64) (float64, error)

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) IsExist

func (c *Cache) IsExist(k string) bool

func (*Cache) LPush

func (c *Cache) LPush(key string, value interface{}) (int64, error)

func (*Cache) Load

func (c *Cache) Load(r io.Reader) error

Add (Gob-serialized) cache items from an io.Reader, excluding any items with keys that already exist in the current cache.

func (*Cache) LoadFile

func (c *Cache) 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 (*Cache) RPop

func (c *Cache) RPop(key string) interface{}

func (*Cache) ReleaseLock

func (c *Cache) ReleaseLock(key string, value string) bool

func (*Cache) Save

func (c *Cache) Save(w io.Writer) (err error)

Write the cache's items (using Gob) to an io.Writer.

func (*Cache) SaveFile

func (c *Cache) SaveFile(fname string) error

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

func (c *Cache) Set(key string, value interface{}, timeout time.Duration) error

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) WithContext

func (c *Cache) WithContext(ctx context.Context) icache.ICache

func (*Cache) WithDB

func (c *Cache) WithDB(db int) icache.ICache

func (*Cache) XAdd

func (c *Cache) XAdd(key, id string, values []string) (string, error)

func (*Cache) XDel

func (c *Cache) XDel(key string, value string) (int64, error)

func (*Cache) XRead

func (c *Cache) XRead(key string, value int64) (interface{}, error)

func (*Cache) ZAdd added in v0.2.12

func (c *Cache) ZAdd(s string, f float64, i interface{}) interface{}

func (*Cache) ZRangeByScore added in v0.2.12

func (c *Cache) ZRangeByScore(s string, i int64, i2 int64) ([]string, error)

func (*Cache) ZRem added in v0.2.12

func (c *Cache) ZRem(s string, i ...interface{}) error

type Option

type Option func(p *config)

func WithAttributes

func WithAttributes(attrs ...string) Option

WithAttributes specifies additional attributes to be added to the span.

func WithCleanupInterval

func WithCleanupInterval(cleanupInterval time.Duration) Option

func WithDefaultExpiration

func WithDefaultExpiration(defaultExpiration time.Duration) Option

func WithLogger

func WithLogger(logger glog.ILogger) Option

WithLogger prevents logger.

func WithTracer

func WithTracer(tracerServer *tracer.Server) Option

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) Delete

func (sc *ShardedCache) Delete(key string) (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) GetLock

func (sc *ShardedCache) GetLock(lockName string, acquireTimeout, lockTimeOut time.Duration) (string, error)

func (*ShardedCache) GetString

func (sc *ShardedCache) GetString(key string) (string, error)

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

func (*ShardedCache) WithDB

func (sc *ShardedCache) WithDB(db int) icache.ICache

func (*ShardedCache) XAdd

func (sc *ShardedCache) XAdd(key, id string, values []string) (string, error)

func (*ShardedCache) XDel

func (sc *ShardedCache) XDel(key string, val string) (int64, error)

func (*ShardedCache) XRead

func (sc *ShardedCache) XRead(key string, val int64) (interface{}, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL