Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultMarshalFunc(value any) ([]byte, error)
- func DefaultUnmarshalFunc(b []byte, value any) error
- func Del(ctx context.Context, key string) error
- func Get(ctx context.Context, key string, v any, opts ...Option) error
- func Has(ctx context.Context, key string) bool
- func IsNotFound(err error) bool
- func RegisterCache(name string, cache Cache) error
- func Set(ctx context.Context, key string, v any, opts ...Option) error
- func SetDefault(driver string) error
- func UnRegisterCache(name string)
- type Cache
- type MarshalFunc
- type Option
- type Options
- type SkipMode
- type Stats
- type UnmarshalFunc
Constants ¶
View Source
const (
CacheKindRedis = "redis"
)
Variables ¶
View Source
var ( ErrDriverNameMiss = errors.New("cache: driverName is empty") ErrCacheMiss = errors.New("cache: key is missing") )
Functions ¶
func DefaultMarshalFunc ¶ added in v0.3.0
func DefaultUnmarshalFunc ¶ added in v0.3.0
func IsNotFound ¶
func RegisterCache ¶
RegisterCache registers a cache driver. It is not safe for concurrent use.
func SetDefault ¶
SetDefault sets the default driver to use the static functions.
func UnRegisterCache ¶ added in v0.4.3
func UnRegisterCache(name string)
UnRegisterCache unregisters a cache driver. It is not safe for concurrent use.
Types ¶
type Cache ¶
type Cache interface { // Get gets the value from cache and unmarshal it to v. Make sure the value is a pointer and zero. Get(ctx context.Context, key string, value any, opts ...Option) error // Set sets the value to cache. Set(ctx context.Context, key string, value any, opts ...Option) error // Has reports whether the value for the given key exists. Has(ctx context.Context, key string) bool // Del deletes the value for the given key. Del(ctx context.Context, key string) error // IsNotFound detect the error weather not found from cache IsNotFound(err error) bool }
Cache is the interface for cache.
type MarshalFunc ¶ added in v0.3.0
type Option ¶ added in v0.3.0
type Option func(*Options)
func WithGetter ¶ added in v0.3.0
WithGetter sets the cache getter.
type Options ¶ added in v0.3.0
type Options struct { // TTL is the cache expiration time. TTL time.Duration // Getter returns value to be cached.call getter to get a value(such as query database) and set cache using c.expiry Getter func(ctx context.Context, key string) (any, error) // SetXX only sets the key if it already exists. SetXX bool // SetNX only sets the key if it does not already exist. SetNX bool // SkipFlags indicator skip level. Skip SkipMode // Raw indicates whether to skip serialization. default is false to keep coroutine safe. // Caches accessed across processes are serialized, that flag Generally used for memory cache. // // false that means serialize value to Item.V. if true, Item.V is raw value but support by implemented Cache. // has implemented Cache: lfu cache Raw bool // Group indicates whether to singleflight. Group bool }
func ApplyOptions ¶ added in v0.3.0
func (*Options) Expiration ¶ added in v0.3.0
type SkipMode ¶ added in v0.3.0
type SkipMode int
SkipMode controls the cache load which level from a combined cache .
const ( SkipLocal SkipMode = 1 << iota SkipRemote // SkipCache skip cache load,means load from source SkipCache = SkipLocal | SkipRemote )
type UnmarshalFunc ¶ added in v0.3.0
Click to show internal directories.
Click to hide internal directories.