cache

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerCache

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

func NewBadgerCache

func NewBadgerCache(dir string, inMemory bool) (*BadgerCache, error)

func NewBadgerCacheDB

func NewBadgerCacheDB(db *badger.DB) *BadgerCache

func (*BadgerCache) Clean

func (c *BadgerCache) Clean() error

func (*BadgerCache) Del

func (c *BadgerCache) Del(key string) error

func (*BadgerCache) Get

func (c *BadgerCache) Get(key string) ([]byte, error)

func (*BadgerCache) PrefixScanKey

func (c *BadgerCache) PrefixScanKey(prefixStr string) ([]string, error)

func (*BadgerCache) Set

func (c *BadgerCache) Set(key string, value interface{}) error

func (*BadgerCache) SetNX

func (c *BadgerCache) SetNX(key string, value interface{}) error

func (*BadgerCache) SetWithTTL

func (c *BadgerCache) SetWithTTL(key string, value string, duration time.Duration) error

type Cache

type Cache interface {
	Get(key string) ([]byte, error)
	Set(key string, value interface{}) error
	Del(key string) error

	// SetWithTTL 设置key,超时时间,注意单位,不能直接使用秒,比如一分钟必须写成 60*time.Second
	SetWithTTL(key string, value string, duration time.Duration) error
}

func NewCache

func NewCache(opts ...OptFunc) (Cache, error)

type MemoryCache

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

func NewMemoryCache

func NewMemoryCache() *MemoryCache

func (*MemoryCache) Del

func (c *MemoryCache) Del(key string) error

func (*MemoryCache) Get

func (c *MemoryCache) Get(k string) ([]byte, error)

func (*MemoryCache) Set

func (c *MemoryCache) Set(key string, value interface{}) error

func (*MemoryCache) SetWithTTL

func (c *MemoryCache) SetWithTTL(key string, value string, duration time.Duration) error

type OptFunc

type OptFunc func(*Options) *Options

func WithCacheDir

func WithCacheDir(cacheDir string) OptFunc

func WithInMemory

func WithInMemory() OptFunc

func WithRedis

func WithRedis(redis *RedisOptions) OptFunc

func WithRedisCmdable

func WithRedisCmdable(redisCmdable redis.Cmdable) OptFunc

type Options

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

type RedisCache

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

func NewRedisCache

func NewRedisCache(options *RedisOptions) (*RedisCache, error)

func NewRedisCacheDB

func NewRedisCacheDB(client redis.Cmdable) (*RedisCache, error)

func (*RedisCache) Del

func (s *RedisCache) Del(key string) error

func (*RedisCache) Get

func (s *RedisCache) Get(key string) ([]byte, error)

func (*RedisCache) Set

func (s *RedisCache) Set(key string, value interface{}) error

func (*RedisCache) SetWithTTL

func (s *RedisCache) SetWithTTL(key string, value string, duration time.Duration) error

type RedisOptions

type RedisOptions struct {
	Address  []string `json:"address" yaml:"address"`
	Username string   `json:"username" yaml:"username"`
	Password string   `json:"password" yaml:"password"`
	DB       int      `json:"db" yaml:"db"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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