cache

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: MIT Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDriverName = "redis"
)

Functions

func Del

func Del(ctx context.Context, key string) error

func Get

func Get(ctx context.Context, key string, v any) error

func Has

func Has(ctx context.Context, key string) bool

func IsNotFound

func IsNotFound(err error) bool

func RegisterCache

func RegisterCache(name string, cache Cache) error

func Set

func Set(ctx context.Context, key string, v any, ttl time.Duration) error

func SetDefault

func SetDefault(driver string) error

func Take

func Take(ctx context.Context, v any, key string, ttl time.Duration, query func() (any, error)) error

Types

type Cache

type Cache interface {
	// Get gets the value from cache and unmarshal it to v.
	Get(ctx context.Context, key string, v any) error
	// Set sets the value to cache.
	Set(ctx context.Context, key string, v any, ttl time.Duration) error
	// Has reports whether 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
	// Take takes the result from cache first, if not found,
	// call query to get a value(such as query database) and set cache using c.expiry, then return the result.
	Take(ctx context.Context, v any, key string, ttl time.Duration, query func() (any, error)) error
	// IsNotFound detect the error weather not found from cache
	IsNotFound(err error) bool
}

Cache is the interface for cache.

func GetCache

func GetCache(driver string) Cache

GetCache return a Cache driver,if it has multi Cache Driver

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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