Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCleanTask ¶ added in v0.60.0
AddCleanTask adds a clean task on given keys.
Types ¶
type Cache ¶
type Cache interface {
cache.Cache
// SetNoExpireCtx Because zero cache set ctx has default expire, so jzero add this method
SetNoExpireCtx(ctx context.Context, key string, val any) error
// GetPrefixKeysCtx get prefix key, give prefix key return all matched key
GetPrefixKeysCtx(ctx context.Context, prefix string) ([]string, error)
// ExpireCtx set key expire
ExpireCtx(ctx context.Context, key string, expire time.Duration) error
}
func NewNode ¶ added in v0.60.0
func NewNode(rds *redis.Redis, barrier syncx.SingleFlight, st *Stat, errNotFound error, opts ...Option, ) Cache
NewNode returns a cacheNode. rds is the underlying redis node or cluster. barrier is the barrier that maybe shared with other cache nodes on cache cluster. st is used to stat the cache. errNotFound defines the error that returned on cache not found. opts are the options that customize the cacheNode.
func NewRedisNode ¶
NewRedisNode returns a cacheNode configured for Redis usage.
type ClusterConf ¶ added in v0.60.0
type ClusterConf []NodeConf
A ClusterConf is the config of a redis cluster that used as cache.
type Option ¶ added in v0.60.0
type Option func(o *Options)
Option defines the method to customize an Options.
func WithCachePrefix ¶ added in v0.60.0
WithCachePrefix returns a func to customize an Options with given cache prefix.
func WithExpiry ¶ added in v0.51.0
WithExpiry returns a func to customize an Options with given expiry.
func WithNotFoundExpiry ¶ added in v0.51.0
WithNotFoundExpiry returns a func to customize an Options with given not found expiry.
type Stat ¶ added in v0.60.0
type Stat struct {
// export the fields to let the unit tests working,
// reside in internal package, doesn't matter.
Total uint64
Hit uint64
Miss uint64
DbFails uint64
// contains filtered or unexported fields
}
A Stat is used to stat the cache.
func (*Stat) IncrementDbFails ¶ added in v0.60.0
func (s *Stat) IncrementDbFails()
IncrementDbFails increments the db fail count.
func (*Stat) IncrementHit ¶ added in v0.60.0
func (s *Stat) IncrementHit()
IncrementHit increments the hit count.
func (*Stat) IncrementMiss ¶ added in v0.60.0
func (s *Stat) IncrementMiss()
IncrementMiss increments the miss count.
func (*Stat) IncrementTotal ¶ added in v0.60.0
func (s *Stat) IncrementTotal()
IncrementTotal increments the total count.