cache

package
v0.0.0-...-225f367 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Del(keys ...string) error
	Get(key string, v interface{}) error
	IsNotFound(err error) bool
	Set(key string, v interface{}) error
	SetWithExpire(key string, v interface{}, expire time.Duration) error
	Take(v interface{}, key string, query func(v interface{}) error) error
	TakeWithExpire(v interface{}, key string, query func(v interface{}, expire time.Duration) error) error
}

Cache interface is used to define the cache implementation.

func NewDefaultCache

func NewDefaultCache(c Config) Cache

NewDefaultCache creates a default cache which is provided by go-zero.

func TodoCache

func TodoCache() Cache

TodoCache returns a non-nil, empty Cache. It implements Cache interface, but cache nothing.

type CachedConn

type CachedConn interface {
	// Exec runs given exec on given keys,
	Exec(exec ExecFn, keys ...string) error
	// QueryRow unmarshals into v with given key and query func.
	QueryRow(v interface{}, query QueryFn, key string) error
	// SetCache sets v into cache with given key.
	SetCache(key string, v interface{}) error
	// DelCache deletes cache with keys.
	DelCache(keys ...string) error
	// GetCache unmarshals cache with given key into v.
	GetCache(key string, v interface{}) error
}

A CachedConn is a DB connection with cache capability.

func NewDefaultCachedConn

func NewDefaultCachedConn(cc Cache) CachedConn

NewDefaultCachedConn creates a cached conn.

type Config

type Config struct {
	Addr        string
	Pass        string
	Expiry      time.Duration
	ErrNotFound error
}

Config cache configure.

type ExecFn

type ExecFn func() error

ExecFn defines the exec method.

type QueryFn

type QueryFn func(v interface{}) error

QueryFn defines the query method.

Jump to

Keyboard shortcuts

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