rcache

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

README

rose-cache

WithLifeWindow 和 WithCleanWindow 的区别

  • WithLifeWindow 是配置生命周期窗口的时间,这个时间是指缓存的生命周期从写入缓存到缓存过期的时间内,缓存在这个时间内是可用的。
  • WithCleanWindow 是配置缓存过期后多久被清除的时间,缓存过期后,在这个时间内缓存依然可以被读取到,但是这个时间内缓存不能被写入。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyEmpty    = errors.New("key is empty")
	ErrKeyNotFound = errors.New("key not found")
	ErrValueEmpty  = errors.New("value is empty")
	ErrNilCache    = errors.New("cache is nil")
)

Functions

This section is empty.

Types

type Cache

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

func NewCache

func NewCache(minute int64, opts ...Option) (*Cache, error)

NewCache 返回一个新的 Cache 实例。 它使用提供的配置选项初始化一个新的 BigCache 实例。 缓存将根据提供的分钟参数具有默认的生命周期。 如果指定了任何选项,将应用于缓存配置。

func (*Cache) Close added in v0.0.2

func (c *Cache) Close()

Close 关闭缓存并释放与之相关的任何资源。 当缓存不再需要时,应调用此方法以确保正确清理。

func (*Cache) Delete

func (c *Cache) Delete(key string) error

Delete 根据提供的键从缓存中删除一个值。 如果键为空或在删除过程中出现任何问题,则返回错误。

func (*Cache) Get

func (c *Cache) Get(key string) ([]byte, error)

Get 根据提供的键从缓存中检索值。 返回值为字节切片,如果键不存在或检索过程中出现其他问题,则返回错误。 此方法是线程安全的。

func (*Cache) GetString

func (c *Cache) GetString(key string) (string, error)

GetString 根据提供的键从缓存中检索值并返回字符串。

func (*Cache) GetValue

func (c *Cache) GetValue(key string, value interface{}) error

GetValue 根据提供的键从缓存中检索值。

func (*Cache) Has added in v0.0.2

func (c *Cache) Has(key string) bool

Has 检查缓存中是否存在某个键。 如果键存在,则返回 true,否则返回 false。 此方法是线程安全的。

func (*Cache) Set

func (c *Cache) Set(key string, value []byte) error

Set 使用提供的键和值在缓存中设置一个值。 如果键为空或在设置操作中出现任何问题,则返回错误。 此方法是线程安全的。

func (*Cache) SetEX added in v0.1.0

func (c *Cache) SetEX(key string, value []byte, expiration time.Duration) error

SetEX 使用过期时间在缓存中设置一个值。 值将在指定的持续时间后从缓存中删除。 如果键为空或在设置操作中出现任何问题,则返回错误。

func (*Cache) SetEXString added in v0.1.0

func (c *Cache) SetEXString(key, value string, expiration time.Duration) error

SetEXString 使用过期时间在缓存中设置一个字符串值。 这是一个便捷方法,先将字符串转换为字节切片,然后调用 SetEX。

func (*Cache) SetEXValue added in v0.1.1

func (c *Cache) SetEXValue(key string, value interface{}, expiration time.Duration) error

SetEXValue 使用过期时间在缓存中设置一个值。 值将在指定的持续时间后从缓存中删除。 如果键为空或在设置操作中出现任何问题,则返回错误。

func (*Cache) SetString

func (c *Cache) SetString(key, value string) error

SetString 使用提供的键和值在缓存中设置一个字符串值。

func (*Cache) SetValue

func (c *Cache) SetValue(key string, value interface{}) error

SetValue 使用提供的键和值在缓存中设置一个值。

type Option added in v0.0.3

type Option func(ctx *context.Context, config *bigcache.Config)

func WithCleanWindow added in v0.0.3

func WithCleanWindow(clean time.Duration) Option

WithCleanWindow 设置缓存的清理频率。 在此时间段内,过期的条目将从缓存中删除。 这有助于保持最佳性能和内存使用,确保过期条目不会滞留在缓存中。

func WithContext added in v0.0.3

func WithContext(ctx context.Context) Option

WithContext 允许为 BigCache 实例设置自定义上下文。 该上下文可用于控制缓存的生命周期,允许进行取消和超时管理。

func WithLifeWindow added in v0.0.3

func WithLifeWindow(life time.Duration) Option

WithLifeWindow 设置缓存中条目的有效期。 超过此时间后,条目将自动从缓存中删除。 这有助于管理内存使用,并确保不会提供过时的数据。

Jump to

Keyboard shortcuts

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