Documentation
¶
Index ¶
- Constants
- Variables
- func FetchOrSave(ctx context.Context, c Cache, key string, value interface{}, ...) error
- func Initialize(t, addr string) error
- func NewContext(ctx context.Context, c Cache) context.Context
- func Register(t string, factory func(opts Options) (Cache, error))
- type Cache
- type Codec
- type Option
- type Options
Constants ¶
View Source
const ( // Memory the cache name of memory Memory = "memory" // Redis the cache name of redis Redis = "redis" // RedisSentinel the cache name of redis sentinel RedisSentinel = "redis+sentinel" )
Variables ¶
View Source
var ( // ErrorNotFound error returns the key value not found in the cache ErrorNotFound = errors.New("Key not found") )
Functions ¶
func FetchOrSave ¶
func FetchOrSave(ctx context.Context, c Cache, key string, value interface{}, builder func() (interface{}, error), expiration ...time.Duration) error
FetchOrSave retrieves the value for the key if present in the cache. Otherwise, it saves the value from the builder and retrieves the value for the key again.
func Initialize ¶
Types ¶
type Cache ¶
type Cache interface {
Contain(ctx context.Context, key string) bool
Delete(ctx context.Context, key string) error
Fetch(ctx context.Context, key string, value interface{}) error
Ping(ctx context.Context) error
Save(ctx context.Context, key string, value interface{}, expiration ...time.Duration) error
Keys(ctx context.Context, prefixes ...string) ([]string, error)
}
type Codec ¶
type Codec interface {
// Encode returns the encoded byte array of v.
Encode(v interface{}) ([]byte, error)
// Decode analyzes the encoded data and stores the result into the v.
Decode(data []byte, v interface{}) error
}
Codec interface for cache
func DefaultCodec ¶
func DefaultCodec() Codec
Click to show internal directories.
Click to hide internal directories.