Documentation
¶
Overview ¶
Package cache provides object caching in memory.
Index ¶
- Variables
- func Has(key string) bool
- func Load(ctx context.Context, key string, loader Loader, opts ...Option) (loadType LoadType, result Result, _ error)
- type Driver
- type HashFunc
- type JSONResult
- type LoadType
- type Loader
- type Option
- type OptionArg
- type Result
- type ResultLoader
- type Shardable
- type Storage
- type ValueResult
Constants ¶
This section is empty.
Variables ¶
var ( Cache Shardable Engine Driver )
Functions ¶
Types ¶
type Driver ¶
type Driver interface {
Load(ctx context.Context, m *sync.Map, key string, loader ResultLoader, arg OptionArg) (loadType LoadType, result Result, err error)
}
Driver loads value from m, if there is no cached value, call the loader to get value, and then stores it into m.
type JSONResult ¶
type JSONResult struct {
// contains filtered or unexported fields
}
JSONResult stores a JSON string.
func (*JSONResult) JSON ¶
func (r *JSONResult) JSON() (string, error)
JSON returns the JSON encoding of the stored value.
func (*JSONResult) Load ¶
func (r *JSONResult) Load(v interface{}) error
Load injects the saved value to v.
type Option ¶
type Option func(*OptionArg)
func ExpireAfterWrite ¶
ExpireAfterWrite sets the expiration time of the cache value after write.
type Result ¶
Result stores a value.
func NewJSONResult ¶
NewJSONResult returns a Result which stores a JSON string.
func NewValueResult ¶
func NewValueResult(v interface{}) Result
NewValueResult returns a Result which stores a `reflect.Value`.
type ResultLoader ¶
ResultLoader returns a wrapper for the source value of the key.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage is a Shardable cache implementation.
func NewStorage ¶
NewStorage returns a new *Storage.
type ValueResult ¶
type ValueResult struct {
// contains filtered or unexported fields
}
ValueResult stores a `reflect.Value`.
func (*ValueResult) JSON ¶
func (r *ValueResult) JSON() (string, error)
JSON returns the JSON encoding of the stored value.
func (*ValueResult) Load ¶
func (r *ValueResult) Load(v interface{}) error
Load injects the saved value to v.