Documentation
¶
Overview ¶
Package apcu 提供了进程内缓存组件。
Index ¶
Constants ¶
View Source
const EmptyValue = "::empty::"
EmptyValue 流量录制时表示空值。
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load 获取 key 对应的缓存值,注意 out 的类型必须和 Store 的时候存入的类 型一致,否则 Load 会失败。但是如果 Store 的时候存入的内容是一个字符串, 那么 out 可以是该字符串 JSON 反序列化之后的类型。
func Store ¶
func Store(ctx context.Context, key string, val interface{}, opts ...StoreOption)
Store 保存 key 及其对应的 val,支持对 key 设置 ttl (过期时间)。另外, 这里的 val 可以是任何值,因此要求 Load 的时候必须保证返回值和这里的 val 是相同类型的,否则 Load 会失败。 但是这里有一个例外情况,考虑到很多场景下,用户需要缓存一个由字符串反序列 化后的对象,所以该库提供了一个功能,就是用户可以 Store 一个字符串,然后 Load 的时候按照指定类型返回。
Types ¶
type StoreOption ¶
type StoreOption func(arg *StoreArg)
Click to show internal directories.
Click to hide internal directories.