Documentation ¶
Index ¶
- Constants
- Variables
- type Cache
- type Item
- type Metrics
- type Option
- func CleanInterval(cleanInterval time.Duration) Option
- func Disabled(disabled bool) Option
- func GetConn(getConn func() redis.Conn) Option
- func Namespace(namespace string) Option
- func OnError(onError func(err error)) Option
- func OnMetric(onMetric func(key string, metricType string, elapsedTime time.Duration)) Option
- func RedisTTLFactor(redisTTLFactor int) Option
- type Options
Constants ¶
View Source
const ( MetricTypeGetMemHit = "get_mem_hit" MetricTypeGetMemMiss = "get_mem_miss" MetricTypeGetMemExpired = "get_mem_expired" MetricTypeGetRedisHit = "get_redis_hit" MetricTypeGetRedisMiss = "get_redis_miss" MetricTypeGetRedisExpired = "get_redis_expired" MetricTypeGetCache = "get_cache" MetricTypeLoad = "load" MetricTypeAsyncLoad = "async_load" MetricTypeSetCache = "set_cache" MetricTypeSetMem = "set_mem" MetricTypeSetRedis = "set_redis" MetricTypeDeleteCache = "del_cache" MetricTypeDeleteMem = "del_mem" MetricTypeDeleteRedis = "del_redis" )
Variables ¶
View Source
var (
ErrIllegalTTL = errors.New("illegal ttl, must be in whole numbers of seconds, no fractions")
)
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { SetObject(ctx context.Context, key string, obj interface{}, ttl time.Duration) error // GetObject loader function f() will be called in case cache all miss // suggest to use object#id as key or any other pattern which can easily extract object, aggregate metric for same object in onMetric GetObject(ctx context.Context, key string, obj interface{}, ttl time.Duration, f func() (interface{}, error)) error Delete(key string) error // Disable GetObject will call loader function in case cache is disabled. Disable() // DeleteFromMem allows to delete key from mem, for test purpose DeleteFromMem(key string) // DeleteFromRedis allows to delete key from redis, for test purpose DeleteFromRedis(key string) error }
type Item ¶
type Option ¶ added in v1.1.8
type Option func(*Options)
func CleanInterval ¶ added in v1.1.8
func RedisTTLFactor ¶ added in v1.1.8
type Options ¶ added in v1.1.8
type Options struct { Namespace string // clean interval for in-memory cache CleanInterval time.Duration // will call loader function when disabled id true Disabled bool // redis ttl = ttl*RedisTTLFactor, data in redis lives longer than memory cache. RedisTTLFactor int // retrieve redis connection GetConn func() redis.Conn // metrics Metric Metrics // must be provided for cache initialization, handle internal error OnError func(err error) }
Click to show internal directories.
Click to hide internal directories.