apcu

package
v1.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package apcu 是进程内缓存,是 PHP APCu 的功能迁移。

Index

Constants

View Source
const Protocol = "apcu"

Variables

This section is empty.

Functions

func Delete

func Delete(key string)

Delete 删除 key 对应的缓存内容。

func Load

func Load(ctx context.Context, key string, out interface{}) (ok bool, err error)

Load 获取 key 对应的缓存值,注意 out 的类型必须和 Store 的时候存入的类 型一致,否则 Load 会失败。但是如果 Store 的时候存入的内容是一个字符串, 那么 out 可以是该字符串 JSON 反序列化之后的类型。

func Range

func Range(f func(key, value interface{}) bool)

Range 遍历缓存的内容。

func Store

func Store(key string, val interface{}, opts ...internal.StoreOption)

Store 保存 key 及其对应的 val,支持对 key 设置 ttl (过期时间)。另外, 这里的 val 可以是任何值,因此要求 Load 的时候必须保证返回值和这里的 val 是相同类型的,否则 Load 会失败。 但是这里有一个例外情况,考虑到很多场景下,用户需要缓存一个由字符串反序列 化后的对象,所以该库提供了一个功能,就是用户可以 Store 一个字符串,然后 Load 的时候按照指定类型返回。

func TTL

TTL 设置 key 的过期时间。

Types

type APCU

type APCU interface {
	Load(ctx context.Context, key string, out interface{}) (ok bool, err error)
	Store(key string, val interface{}, opts ...internal.StoreOption)
	Range(f func(key, value interface{}) bool)
	Delete(key string)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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