Documentation
¶
Index ¶
- Variables
- func Del(ctx context.Context, key string) error
- func Get(ctx context.Context, key string, v any) 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, ttl time.Duration) error
- func SetDefault(driver string) error
- func Take(ctx context.Context, v any, key string, ttl time.Duration, ...) error
- type Cache
Constants ¶
This section is empty.
Variables ¶
View Source
var (
DefaultDriverName = "redis"
)
Functions ¶
func IsNotFound ¶
func RegisterCache ¶
func SetDefault ¶
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.
Click to show internal directories.
Click to hide internal directories.