cache

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MemoryInT cacheType = "memory"
	RedisT    cacheType = "redis"
	MemCacheT cacheType = "memcache"
)
View Source
const (
	DEFAULT = time.Duration(0)
	FOREVER = time.Duration(-1)
)

Variables

View Source
var (
	UnKnownCacheError         = NewCacheError(11001, "unknown cache error")
	UnsupportedCacheTypeError = NewCacheError(11002, "unsupported cache type,supported cache type:) "+strings.Join(supportedCacheType, ","))
	AutoInitCacheError        = NewCacheError(11003, "auto init cache error")
	NoKeyCacheError           = NewCacheError(11004, "no key cache error")
)

Functions

func MemCacheConfig

func MemCacheConfig() map[string]interface{}

func MemoryInConfig

func MemoryInConfig() map[string]interface{}

Types

type Cache

type Cache interface {
	Get(key string, value interface{}) error
	Set(key string, value interface{}, expire time.Duration) error
	Add(key string, value interface{}, expire time.Duration) error
	Replace(key string, data interface{}, expire time.Duration) error
	Delete(key string) error
	Incr(key string, data int64) (int64, error)
	Flush() error
}

func NewAutoCache

func NewAutoCache(cc CacheConfig) (Cache, error)

auto select cache type: Redis,MemCache,MemoryIn

func NewCache

func NewCache(c cacheType, cc CacheConfig) (Cache, error)

supported cache type: Redis,MemCache,MemoryIn

type CacheConfig

type CacheConfig func() map[string]interface{}

type CacheError

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

func NewCacheError

func NewCacheError(code int, ds ...string) CacheError

func (CacheError) Error

func (c CacheError) Error() string

func (CacheError) WithDetails

func (c CacheError) WithDetails(ds ...string) CacheError

type MemCache

type MemCache struct {
	Cache
}

func NewMemCache

func NewMemCache(cc CacheConfig) (*MemCache, error)

type MemoryInCache

type MemoryInCache struct {
	Cache
}

func NewMemoryInCache

func NewMemoryInCache(cc CacheConfig) (*MemoryInCache, error)

type RedisCache

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

func NewRedisCache

func NewRedisCache(cc CacheConfig) (*RedisCache, error)

func (*RedisCache) Add

func (rc *RedisCache) Add(key string, value interface{}, expire time.Duration) error

func (*RedisCache) Conn

func (rc *RedisCache) Conn() redis.Conn

func (*RedisCache) Delete

func (rc *RedisCache) Delete(key string) error

func (*RedisCache) Flush

func (rc *RedisCache) Flush() error

func (*RedisCache) Get

func (rc *RedisCache) Get(key string, value interface{}) error

func (*RedisCache) Incr

func (rc *RedisCache) Incr(key string, delta int64) (int64, error)

func (*RedisCache) Replace

func (rc *RedisCache) Replace(key string, value interface{}, expire time.Duration) error

func (*RedisCache) Set

func (rc *RedisCache) Set(key string, value interface{}, expire time.Duration) error

type RedisConfig

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

Jump to

Keyboard shortcuts

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