store

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2021 License: MIT Imports: 10 Imported by: 27

Documentation

Index

Constants

View Source
const (
	// BigcacheType represents the storage type as a string value
	BigcacheType = "bigcache"
	// BigcacheTagPattern represents the tag pattern to be used as a key in specified storage
	BigcacheTagPattern = "gocache_tag_%s"
)
View Source
const (
	// FreecacheType represents the storage type as a string value
	FreecacheType = "freecache"
	// FreecacheTagPattern represents the tag pattern to be used as a key in specified storage
	FreecacheTagPattern = "freecache_tag_%s"
)
View Source
const (
	// GoCacheType represents the storage type as a string value
	GoCacheType = "go-cache"
	// GoCacheTagPattern represents the tag pattern to be used as a key in specified storage
	GoCacheTagPattern = "gocache_tag_%s"
)
View Source
const (
	// MemcacheType represents the storage type as a string value
	MemcacheType = "memcache"
	// MemcacheTagPattern represents the tag pattern to be used as a key in specified storage
	MemcacheTagPattern = "gocache_tag_%s"
)
View Source
const (
	// PegasusType represents the storage type as a string value
	PegasusType = "pegasus"
	// PegasusTagPattern represents the tag pattern to be used as a key in specified storage
	PegasusTagPattern = "gocache_tag_%s"
	// Pegasus ttl(time-to-live) in seconds: -1 if ttl is not set; -2 if entry doesn't exist
	PegasusNOTTL   = -1
	PegasusNOENTRY = -2

	DefaultTable             = "gocache_pegasus"
	DefaultTablePartitionNum = 4
	DefaultScanNum           = 100
)
View Source
const (
	// RedisType represents the storage type as a string value
	RedisType = "redis"
	// RedisTagPattern represents the tag pattern to be used as a key in specified storage
	RedisTagPattern = "gocache_tag_%s"
)
View Source
const (
	// RedisType represents the storage type as a string value
	RedisClusterType = "rediscluster"
	// RedisTagPattern represents the tag pattern to be used as a key in specified storage
	RedisClusterTagPattern = "gocache_tag_%s"
)
View Source
const (
	// RistrettoType represents the storage type as a string value
	RistrettoType = "ristretto"
	// RistrettoTagPattern represents the tag pattern to be used as a key in specified storage
	RistrettoTagPattern = "gocache_tag_%s"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BigcacheClientInterface

type BigcacheClientInterface interface {
	Get(key string) ([]byte, error)
	Set(key string, entry []byte) error
	Delete(key string) error
	Reset() error
}

BigcacheClientInterface represents a allegro/bigcache client

type BigcacheStore

type BigcacheStore struct {
	// contains filtered or unexported fields
}

BigcacheStore is a store for Bigcache

func NewBigcache

func NewBigcache(client BigcacheClientInterface, options *Options) *BigcacheStore

NewBigcache creates a new store to Bigcache instance(s)

func (*BigcacheStore) Clear added in v1.0.0

func (s *BigcacheStore) Clear() error

Clear resets all data in the store

func (*BigcacheStore) Delete added in v0.2.0

func (s *BigcacheStore) Delete(key interface{}) error

Delete removes data from Bigcache for given key identifier

func (*BigcacheStore) Get

func (s *BigcacheStore) Get(key interface{}) (interface{}, error)

Get returns data stored from a given key

func (*BigcacheStore) GetType

func (s *BigcacheStore) GetType() string

GetType returns the store type

func (*BigcacheStore) GetWithTTL added in v1.1.0

func (s *BigcacheStore) GetWithTTL(key interface{}) (interface{}, time.Duration, error)

GetWithTTL returns data stored from a given key and its corresponding TTL

func (*BigcacheStore) Invalidate added in v0.2.0

func (s *BigcacheStore) Invalidate(options InvalidateOptions) error

Invalidate invalidates some cache data in Bigcache for given options

func (*BigcacheStore) Set

func (s *BigcacheStore) Set(key interface{}, value interface{}, options *Options) error

Set defines data in Bigcache for given key identifier

type FreecacheClientInterface added in v1.1.0

type FreecacheClientInterface interface {
	Get(key []byte) (value []byte, err error)
	GetInt(key int64) (value []byte, err error)
	TTL(key []byte) (timeLeft uint32, err error)
	Set(key, value []byte, expireSeconds int) (err error)
	SetInt(key int64, value []byte, expireSeconds int) (err error)
	Del(key []byte) (affected bool)
	DelInt(key int64) (affected bool)
	Clear()
}

FreecacheClientInterface represents a coocood/freecache client

type FreecacheStore added in v1.1.0

type FreecacheStore struct {
	// contains filtered or unexported fields
}

FreecacheStore is a store for freecache

func NewFreecache added in v1.1.0

func NewFreecache(client FreecacheClientInterface, options *Options) *FreecacheStore

NewFreecache creates a new store to freecache instance(s)

func (*FreecacheStore) Clear added in v1.1.0

func (f *FreecacheStore) Clear() error

Clear resets all data in the store

func (*FreecacheStore) Delete added in v1.1.0

func (f *FreecacheStore) Delete(key interface{}) error

Delete deletes an item in the cache by key and returns err or nil if a delete occurred

func (*FreecacheStore) Get added in v1.1.0

func (f *FreecacheStore) Get(key interface{}) (interface{}, error)

Get returns data stored from a given key. It returns the value or not found error

func (*FreecacheStore) GetType added in v1.1.0

func (f *FreecacheStore) GetType() string

GetType returns the store type

func (*FreecacheStore) GetWithTTL added in v1.1.0

func (f *FreecacheStore) GetWithTTL(key interface{}) (interface{}, time.Duration, error)

GetWithTTL returns data stored from a given key and its corresponding TTL

func (*FreecacheStore) Invalidate added in v1.1.0

func (f *FreecacheStore) Invalidate(options InvalidateOptions) error

Invalidate invalidates some cache data in freecache for given options

func (*FreecacheStore) Set added in v1.1.0

func (f *FreecacheStore) Set(key interface{}, value interface{}, options *Options) error

Set sets a key, value and expiration for a cache entry and stores it in the cache. If the key is larger than 65535 or value is larger than 1/1024 of the cache size, the entry will not be written to the cache. expireSeconds <= 0 means no expire, but it can be evicted when cache is full.

type GoCacheClientInterface added in v1.2.0

type GoCacheClientInterface interface {
	Get(k string) (interface{}, bool)
	GetWithExpiration(k string) (interface{}, time.Time, bool)
	Set(k string, x interface{}, d time.Duration)
	Delete(k string)
	Flush()
}

GoCacheClientInterface represents a github.com/patrickmn/go-cache client

type GoCacheStore added in v1.2.0

type GoCacheStore struct {
	// contains filtered or unexported fields
}

GoCacheStore is a store for GoCache (memory) library

func NewGoCache added in v1.2.0

func NewGoCache(client GoCacheClientInterface, options *Options) *GoCacheStore

NewGoCache creates a new store to GoCache (memory) library instance

func (*GoCacheStore) Clear added in v1.2.0

func (s *GoCacheStore) Clear() error

Clear resets all data in the store

func (*GoCacheStore) Delete added in v1.2.0

func (s *GoCacheStore) Delete(key interface{}) error

Delete removes data in GoCache memoey cache for given key identifier

func (*GoCacheStore) Get added in v1.2.0

func (s *GoCacheStore) Get(key interface{}) (interface{}, error)

Get returns data stored from a given key

func (*GoCacheStore) GetType added in v1.2.0

func (s *GoCacheStore) GetType() string

GetType returns the store type

func (*GoCacheStore) GetWithTTL added in v1.2.0

func (s *GoCacheStore) GetWithTTL(key interface{}) (interface{}, time.Duration, error)

GetWithTTL returns data stored from a given key and its corresponding TTL

func (*GoCacheStore) Invalidate added in v1.2.0

func (s *GoCacheStore) Invalidate(options InvalidateOptions) error

Invalidate invalidates some cache data in GoCache memoey cache for given options

func (*GoCacheStore) Set added in v1.2.0

func (s *GoCacheStore) Set(key interface{}, value interface{}, options *Options) error

Set defines data in GoCache memoey cache for given key identifier

type InvalidateOptions added in v0.2.0

type InvalidateOptions struct {
	// Tags allows to specify associated tags to the current value
	Tags []string
}

InvalidateOptions represents the cache invalidation available options

func (InvalidateOptions) TagsValue added in v0.2.0

func (o InvalidateOptions) TagsValue() []string

TagsValue returns the tags option value

type MemcacheClientInterface

type MemcacheClientInterface interface {
	Get(key string) (item *memcache.Item, err error)
	Set(item *memcache.Item) error
	Delete(item string) error
	FlushAll() error
}

MemcacheClientInterface represents a bradfitz/gomemcache client

type MemcacheStore

type MemcacheStore struct {
	// contains filtered or unexported fields
}

MemcacheStore is a store for Memcache

func NewMemcache

func NewMemcache(client MemcacheClientInterface, options *Options) *MemcacheStore

NewMemcache creates a new store to Memcache instance(s)

func (*MemcacheStore) Clear added in v1.0.0

func (s *MemcacheStore) Clear() error

Clear resets all data in the store

func (*MemcacheStore) Delete added in v0.2.0

func (s *MemcacheStore) Delete(key interface{}) error

Delete removes data from Memcache for given key identifier

func (*MemcacheStore) Get

func (s *MemcacheStore) Get(key interface{}) (interface{}, error)

Get returns data stored from a given key

func (*MemcacheStore) GetType

func (s *MemcacheStore) GetType() string

GetType returns the store type

func (*MemcacheStore) GetWithTTL added in v1.1.0

func (s *MemcacheStore) GetWithTTL(key interface{}) (interface{}, time.Duration, error)

GetWithTTL returns data stored from a given key and its corresponding TTL

func (*MemcacheStore) Invalidate added in v0.2.0

func (s *MemcacheStore) Invalidate(options InvalidateOptions) error

Invalidate invalidates some cache data in Redis for given options

func (*MemcacheStore) Set

func (s *MemcacheStore) Set(key interface{}, value interface{}, options *Options) error

Set defines data in Memcache for given key identifier

type Options

type Options struct {
	// Cost corresponds to the memory capacity used by the item when setting a value
	// Actually it seems to be used by Ristretto library only
	Cost int64

	// Expiration allows to specify an expiration time when setting a value
	Expiration time.Duration

	// Tags allows to specify associated tags to the current value
	Tags []string
}

Options represents the cache store available options

func (Options) CostValue

func (o Options) CostValue() int64

CostValue returns the allocated memory capacity

func (Options) ExpirationValue

func (o Options) ExpirationValue() time.Duration

ExpirationValue returns the expiration option value

func (Options) TagsValue added in v0.2.0

func (o Options) TagsValue() []string

TagsValue returns the tags option value

type OptionsPegasus added in v1.2.0

type OptionsPegasus struct {
	Options
	MetaServers []string

	TableName         string
	TablePartitionNum int
	TableScanNum      int
}

OptionsPegasus is options of Pegasus

type PegasusStore added in v1.2.0

type PegasusStore struct {
	// contains filtered or unexported fields
}

PegasusStore is a store for Pegasus

func NewPegasus added in v1.2.0

func NewPegasus(ctx context.Context, options *OptionsPegasus) (*PegasusStore, error)

NewPegasus creates a new store to pegasus instance(s)

func (*PegasusStore) Clear added in v1.2.0

func (p *PegasusStore) Clear(ctx context.Context) error

Clear resets all data in the store

func (*PegasusStore) Close added in v1.2.0

func (p *PegasusStore) Close() error

Close when exit store

func (*PegasusStore) Delete added in v1.2.0

func (p *PegasusStore) Delete(ctx context.Context, key interface{}) error

Delete removes data from Pegasus for given key identifier

func (*PegasusStore) Get added in v1.2.0

func (p *PegasusStore) Get(ctx context.Context, key interface{}) (interface{}, error)

Get returns data stored from a given key

func (*PegasusStore) GetType added in v1.2.0

func (p *PegasusStore) GetType() string

GetType returns the store type

func (*PegasusStore) GetWithTTL added in v1.2.0

func (p *PegasusStore) GetWithTTL(ctx context.Context, key interface{}) (interface{}, time.Duration, error)

GetWithTTL returns data stored from a given key and its corresponding TTL

func (*PegasusStore) Invalidate added in v1.2.0

func (p *PegasusStore) Invalidate(ctx context.Context, options InvalidateOptions) error

Invalidate invalidates some cache data in Pegasus for given options

func (*PegasusStore) Set added in v1.2.0

func (p *PegasusStore) Set(ctx context.Context, key, value interface{}, options *Options) error

Set defines data in Pegasus for given key identifier

type RedisClientInterface

type RedisClientInterface interface {
	Get(ctx context.Context, key string) *redis.StringCmd
	TTL(ctx context.Context, key string) *redis.DurationCmd
	Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd
	Set(ctx context.Context, key string, values interface{}, expiration time.Duration) *redis.StatusCmd
	Del(ctx context.Context, keys ...string) *redis.IntCmd
	FlushAll(ctx context.Context) *redis.StatusCmd
	SAdd(ctx context.Context, key string, members ...interface{}) *redis.IntCmd
	SMembers(ctx context.Context, key string) *redis.StringSliceCmd
}

RedisClientInterface represents a go-redis/redis client

type RedisClusterClientInterface added in v1.2.0

type RedisClusterClientInterface interface {
	Get(ctx context.Context, key string) *redis.StringCmd
	TTL(ctx context.Context, key string) *redis.DurationCmd
	Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd
	Set(ctx context.Context, key string, values interface{}, expiration time.Duration) *redis.StatusCmd
	Del(ctx context.Context, keys ...string) *redis.IntCmd
	FlushAll(ctx context.Context) *redis.StatusCmd
	SAdd(ctx context.Context, key string, members ...interface{}) *redis.IntCmd
	SMembers(ctx context.Context, key string) *redis.StringSliceCmd
}

RedisClusterClientInterface represents a go-redis/redis clusclient

type RedisClusterStore added in v1.2.0

type RedisClusterStore struct {
	// contains filtered or unexported fields
}

RedisStore is a store for Redis

func NewRedisCluster added in v1.2.0

func NewRedisCluster(client RedisClusterClientInterface, options *Options) *RedisClusterStore

NewRedis creates a new store to Redis instance(s)

func (*RedisClusterStore) Clear added in v1.2.0

func (s *RedisClusterStore) Clear(ctx context.Context) error

Clear resets all data in the store

func (*RedisClusterStore) Delete added in v1.2.0

func (s *RedisClusterStore) Delete(ctx context.Context, key interface{}) error

Delete removes data from Redis for given key identifier

func (*RedisClusterStore) Get added in v1.2.0

func (s *RedisClusterStore) Get(ctx context.Context, key interface{}) (interface{}, error)

Get returns data stored from a given key

func (*RedisClusterStore) GetType added in v1.2.0

func (s *RedisClusterStore) GetType() string

GetType returns the store type

func (*RedisClusterStore) GetWithTTL added in v1.2.0

func (s *RedisClusterStore) GetWithTTL(ctx context.Context, key interface{}) (interface{}, time.Duration, error)

GetWithTTL returns data stored from a given key and its corresponding TTL

func (*RedisClusterStore) Invalidate added in v1.2.0

func (s *RedisClusterStore) Invalidate(ctx context.Context, options InvalidateOptions) error

Invalidate invalidates some cache data in Redis for given options

func (*RedisClusterStore) Set added in v1.2.0

func (s *RedisClusterStore) Set(ctx context.Context, key interface{}, value interface{}, options *Options) error

Set defines data in Redis for given key identifier

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

RedisStore is a store for Redis

func NewRedis

func NewRedis(client RedisClientInterface, options *Options) *RedisStore

NewRedis creates a new store to Redis instance(s)

func (*RedisStore) Clear added in v1.0.0

func (s *RedisStore) Clear(ctx context.Context) error

Clear resets all data in the store

func (*RedisStore) Delete added in v0.2.0

func (s *RedisStore) Delete(ctx context.Context, key interface{}) error

Delete removes data from Redis for given key identifier

func (*RedisStore) Get

func (s *RedisStore) Get(ctx context.Context, key interface{}) (interface{}, error)

Get returns data stored from a given key

func (*RedisStore) GetType

func (s *RedisStore) GetType() string

GetType returns the store type

func (*RedisStore) GetWithTTL added in v1.1.0

func (s *RedisStore) GetWithTTL(ctx context.Context, key interface{}) (interface{}, time.Duration, error)

GetWithTTL returns data stored from a given key and its corresponding TTL

func (*RedisStore) Invalidate added in v0.2.0

func (s *RedisStore) Invalidate(ctx context.Context, options InvalidateOptions) error

Invalidate invalidates some cache data in Redis for given options

func (*RedisStore) Set

func (s *RedisStore) Set(ctx context.Context, key interface{}, value interface{}, options *Options) error

Set defines data in Redis for given key identifier

type RistrettoClientInterface

type RistrettoClientInterface interface {
	Get(key interface{}) (interface{}, bool)
	SetWithTTL(key, value interface{}, cost int64, ttl time.Duration) bool
	Del(key interface{})
	Clear()
}

RistrettoClientInterface represents a dgraph-io/ristretto client

type RistrettoStore

type RistrettoStore struct {
	// contains filtered or unexported fields
}

RistrettoStore is a store for Ristretto (memory) library

func NewRistretto

func NewRistretto(client RistrettoClientInterface, options *Options) *RistrettoStore

NewRistretto creates a new store to Ristretto (memory) library instance

func (*RistrettoStore) Clear added in v1.0.0

func (s *RistrettoStore) Clear() error

Clear resets all data in the store

func (*RistrettoStore) Delete added in v0.2.0

func (s *RistrettoStore) Delete(key interface{}) error

Delete removes data in Ristretto memoey cache for given key identifier

func (*RistrettoStore) Get

func (s *RistrettoStore) Get(key interface{}) (interface{}, error)

Get returns data stored from a given key

func (*RistrettoStore) GetType

func (s *RistrettoStore) GetType() string

GetType returns the store type

func (*RistrettoStore) GetWithTTL added in v1.1.0

func (s *RistrettoStore) GetWithTTL(key interface{}) (interface{}, time.Duration, error)

GetWithTTL returns data stored from a given key and its corresponding TTL

func (*RistrettoStore) Invalidate added in v0.2.0

func (s *RistrettoStore) Invalidate(options InvalidateOptions) error

Invalidate invalidates some cache data in Redis for given options

func (*RistrettoStore) Set

func (s *RistrettoStore) Set(key interface{}, value interface{}, options *Options) error

Set defines data in Ristretto memoey cache for given key identifier

type StoreInterface

type StoreInterface interface {
	Get(key interface{}) (interface{}, error)
	GetWithTTL(key interface{}) (interface{}, time.Duration, error)
	Set(key interface{}, value interface{}, options *Options) error
	Delete(key interface{}) error
	Invalidate(options InvalidateOptions) error
	Clear() error
	GetType() string
}

StoreInterface is the interface for all available stores

Directories

Path Synopsis
bigcache module
freecache module
go_cache module
hazelcast module
memcache module
pegasus module
redis module
rediscluster module
ristretto module
rueidis module

Jump to

Keyboard shortcuts

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