x

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTTL int64 = 86400 * 10 * 366

Functions

func CreateKey

func CreateKey(prefix bool, sep string, visual string, args ...interface{}) string

CreateKey will generate a key based on the input arguments. When prefix is true, the caller's name will be used to prefix the key in an attempt to make it unique. The args can also be separated using sep. visual performs no functionality. It is used at code level to visually see how the key is structured.

func CreateKeyStruct

func CreateKeyStruct(strct interface{}) string

CreateKeyStruct generates a key by converting a struct into a JSON object.

func Hash

func Hash(key string) string

Hash returns a crc32 hashed version of key.

Types

type Cachex

type Cachex struct {
	// contains filtered or unexported fields
}

Cachex 缓存处理类

func New

func New(storage cache.Cache, querier Querier, defaultTTL ...int64) (c *Cachex)

New 新建缓存处理对象

func NewFromPool added in v0.7.0

func NewFromPool(storage cache.Cache, querier Querier, defaultTTL ...int64) (c *Cachex)

func (*Cachex) Del

func (c *Cachex) Del(ctx context.Context, keys ...string) error

Del 删除

func (*Cachex) Get

func (c *Cachex) Get(ctx context.Context, key string, value interface{}, opts ...GetOption) error

Get 获取

func (*Cachex) Init added in v0.6.3

func (c *Cachex) Init(storage cache.Cache, querier Querier, defaultTTL ...int64) *Cachex

func (*Cachex) Release added in v0.6.3

func (c *Cachex) Release()

func (*Cachex) Reset added in v0.6.3

func (c *Cachex) Reset() *Cachex

func (*Cachex) Set

func (c *Cachex) Set(ctx context.Context, key string, value interface{}, expire int64) error

Set 更新

func (*Cachex) UseStaleWhenError

func (c *Cachex) UseStaleWhenError(use bool) *Cachex

UseStaleWhenError 设置当查询发生错误时,使用过期的缓存数据。该特性需要Storage支持(Get返回过期的缓存数据和Expired错误实现)。默认关闭。

type GetOption

type GetOption func(*Options)

GetOption Get方法的可选参数项结构,不需要直接调用。

func AddTTL added in v0.6.2

func AddTTL(ttl int64) GetOption

func DisableCacheUsage

func DisableCacheUsage(disableCacheUsage bool) GetOption

func Query

func Query(querier Querier) GetOption

Query 为Get操作定制查询过程

func TTL

func TTL(ttl int64) GetOption

TTL 为Get操作定制TTL

func UseFreshData

func UseFreshData(useFreshData bool) GetOption

type Options added in v0.6.0

type Options struct {
	// contains filtered or unexported fields
}

Options Get方法的可选参数项

func (*Options) AddTTL added in v0.6.2

func (o *Options) AddTTL(ttl int64)

func (*Options) SetDisableCacheUsage added in v0.6.0

func (o *Options) SetDisableCacheUsage(disableCacheUsage bool)

func (*Options) SetQuerier added in v0.6.0

func (o *Options) SetQuerier(querier Querier)

func (*Options) SetTTL added in v0.6.0

func (o *Options) SetTTL(ttl int64)

func (*Options) SetUseFreshData added in v0.6.0

func (o *Options) SetUseFreshData(useFreshData bool)

type Querier

type Querier interface {
	Query() error
}

Querier 查询接口

type QueryFunc

type QueryFunc func() error

QueryFunc 查询过程签名

func (QueryFunc) Query

func (q QueryFunc) Query() error

Query 查询过程实现Querier接口

Jump to

Keyboard shortcuts

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