cache

package
v0.61.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2025 License: MIT Imports: 22 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCleanTask added in v0.60.0

func AddCleanTask(task func() error, keys ...string)

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

func NewRedisNode(rds *redis.Redis, errNotFound error, opts ...Option) Cache

NewRedisNode returns a cacheNode configured for Redis usage.

func NewRedisNodeWithCachePrefix added in v0.60.0

func NewRedisNodeWithCachePrefix(rds *redis.Redis, errNotFound error, cachePrefix string, opts ...Option) Cache

NewRedisNodeWithCachePrefix returns a cacheNode configured for Redis usage with cache prefix.

type ClusterConf added in v0.60.0

type ClusterConf []NodeConf

A ClusterConf is the config of a redis cluster that used as cache.

type NodeConf added in v0.60.0

type NodeConf struct {
	redis.RedisConf
	Weight int `json:",default=100"`
}

A NodeConf is the config of a redis node 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

func WithCachePrefix(prefix string) Option

WithCachePrefix returns a func to customize an Options with given cache prefix.

func WithExpiry added in v0.51.0

func WithExpiry(expiry time.Duration) Option

WithExpiry returns a func to customize an Options with given expiry.

func WithNotFoundExpiry added in v0.51.0

func WithNotFoundExpiry(expiry time.Duration) Option

WithNotFoundExpiry returns a func to customize an Options with given not found expiry.

type Options added in v0.60.0

type Options struct {
	Expiry         time.Duration
	NotFoundExpiry time.Duration
	CachePrefix    string
}

Options is used to store the cache options.

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 NewStat added in v0.60.0

func NewStat(name string) *Stat

NewStat returns a Stat.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL