cache

package
v0.13.9 Latest Latest
Warning

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

Go to latest
Published: May 28, 2022 License: MIT Imports: 6 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCacheType = errors.New("invalid cache type")

ErrInvalidCacheType is error for invalid cache type.

Functions

This section is empty.

Types

type CacheType

type CacheType int8

CacheType is type for cache.

const (
	NoCache CacheType = iota
	InMemory
	Redis
	Memcache
)

Available types for cache.

type Cacher

type Cacher interface {
	// Get data from cache. The returned value will be
	// assigned to param `data`. Param `data` should
	// be a pointer just like when using json.Unmarshal.
	Get(key string, data interface{}) error
	// Save data to cache. Set and Get should be using
	// the same encoding method. For example, json.Marshal
	// for Set and json.Unmarshal for Get.
	Set(key string, data interface{}, ttl ...time.Duration) error
	// Delete data from cache.
	Delete(key string) error
	// Close cache connection.
	Close() error
}

Cacher is caching interface.

See usage example in example folder.

func New

func New(cacheType CacheType, address string, password string, expiredTime time.Duration) (Cacher, error)

New to create new cache client depends on the type.

Directories

Path Synopsis
Package bigcache is a wrapper of the original "github.com/allegro/bigcache" library.
Package bigcache is a wrapper of the original "github.com/allegro/bigcache" library.
Package memcache is a wrapper of the original "github.com/bradfitz/gomemcache/memcache" library.
Package memcache is a wrapper of the original "github.com/bradfitz/gomemcache/memcache" library.
Package nocache is a mock of caching.
Package nocache is a mock of caching.
Package redis is a wrapper of the original "github.com/go-redis/redis" library.
Package redis is a wrapper of the original "github.com/go-redis/redis" library.

Jump to

Keyboard shortcuts

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