storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMemStoreConfig = &MemStoreConfig{
	MaxSize: 1000,
}
View Source
var (
	ErrCacheNotFound = errors.New("cache not found")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	TTL    int64
	Debug  bool
	Logger util.LoggerInterface
}

type DataStorage

type DataStorage interface {
	Init(config *Config) error
	CleanCache(ctx context.Context) error

	// read
	BatchKeyExist(ctx context.Context, keys []string) (bool, error)
	KeyExists(ctx context.Context, key string) (bool, error)
	GetValue(ctx context.Context, key string) (string, error)
	BatchGetValues(ctx context.Context, keys []string) ([]string, error)

	// write
	DeleteKeysWithPrefix(ctx context.Context, keyPrefix string) error
	DeleteKey(ctx context.Context, key string) error
	BatchDeleteKeys(ctx context.Context, keys []string) error
	BatchSetKeys(ctx context.Context, kvs []util.Kv) error
	SetKey(ctx context.Context, kv util.Kv) error
}

type Gcache

type Gcache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewGcache

func NewGcache(builder *gcache.CacheBuilder) *Gcache

func (*Gcache) BatchDeleteKeys

func (g *Gcache) BatchDeleteKeys(ctx context.Context, keys []string) error

func (*Gcache) BatchGetValues

func (g *Gcache) BatchGetValues(ctx context.Context, keys []string) ([]string, error)

func (*Gcache) BatchKeyExist

func (g *Gcache) BatchKeyExist(ctx context.Context, keys []string) (bool, error)

func (*Gcache) BatchSetKeys

func (g *Gcache) BatchSetKeys(ctx context.Context, kvs []util.Kv) error

func (*Gcache) CleanCache

func (g *Gcache) CleanCache(ctx context.Context) error

func (*Gcache) DeleteKey

func (g *Gcache) DeleteKey(ctx context.Context, key string) error

func (*Gcache) DeleteKeysWithPrefix

func (g *Gcache) DeleteKeysWithPrefix(ctx context.Context, keyPrefix string) error

func (*Gcache) GetValue

func (g *Gcache) GetValue(ctx context.Context, key string) (string, error)

func (*Gcache) Init

func (g *Gcache) Init(config *Config) error

func (*Gcache) KeyExists

func (g *Gcache) KeyExists(ctx context.Context, key string) (bool, error)

func (*Gcache) SetKey

func (g *Gcache) SetKey(ctx context.Context, kv util.Kv) error

type MemStoreConfig

type MemStoreConfig struct {
	MaxSize int64 // maximal items in primary cache
}

type Memory

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

func NewMem

func NewMem(config ...*MemStoreConfig) *Memory

func (*Memory) BatchDeleteKeys

func (m *Memory) BatchDeleteKeys(ctx context.Context, keys []string) error

func (*Memory) BatchGetValues

func (m *Memory) BatchGetValues(ctx context.Context, keys []string) ([]string, error)

func (*Memory) BatchKeyExist

func (m *Memory) BatchKeyExist(ctx context.Context, keys []string) (bool, error)

func (*Memory) BatchSetKeys

func (m *Memory) BatchSetKeys(ctx context.Context, kvs []util.Kv) error

func (*Memory) CleanCache

func (m *Memory) CleanCache(ctx context.Context) error

func (*Memory) DeleteKey

func (m *Memory) DeleteKey(ctx context.Context, key string) error

func (*Memory) DeleteKeysWithPrefix

func (m *Memory) DeleteKeysWithPrefix(ctx context.Context, keyPrefix string) error

func (*Memory) GetValue

func (m *Memory) GetValue(ctx context.Context, key string) (string, error)

func (*Memory) Init

func (m *Memory) Init(conf *Config) error

func (*Memory) KeyExists

func (m *Memory) KeyExists(ctx context.Context, key string) (bool, error)

func (*Memory) SetKey

func (m *Memory) SetKey(ctx context.Context, kv util.Kv) error

type Redis

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

func NewRedis

func NewRedis(config ...*RedisStoreConfig) *Redis

func (*Redis) BatchDeleteKeys

func (r *Redis) BatchDeleteKeys(ctx context.Context, keys []string) error

func (*Redis) BatchGetValues

func (r *Redis) BatchGetValues(ctx context.Context, keys []string) ([]string, error)

func (*Redis) BatchKeyExist

func (r *Redis) BatchKeyExist(ctx context.Context, keys []string) (bool, error)

func (*Redis) BatchSetKeys

func (r *Redis) BatchSetKeys(ctx context.Context, kvs []util.Kv) error

func (*Redis) CleanCache

func (r *Redis) CleanCache(ctx context.Context) error

func (*Redis) DeleteKey

func (r *Redis) DeleteKey(ctx context.Context, key string) error

func (*Redis) DeleteKeysWithPrefix

func (r *Redis) DeleteKeysWithPrefix(ctx context.Context, keyPrefix string) error

func (*Redis) GetValue

func (r *Redis) GetValue(ctx context.Context, key string) (data string, err error)

func (*Redis) Init

func (r *Redis) Init(conf *Config) error

func (*Redis) KeyExists

func (r *Redis) KeyExists(ctx context.Context, key string) (bool, error)

func (*Redis) SetKey

func (r *Redis) SetKey(ctx context.Context, kv util.Kv) error

type RedisStoreConfig

type RedisStoreConfig struct {
	KeyPrefix string // key prefix will be random if not set

	Client  redis.UniversalClient // if Client is not nil, Options will be ignored
	Options *redis.UniversalOptions
}

Jump to

Keyboard shortcuts

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