Documentation
¶
Overview ¶
Package cache 提供 nraos 使用的通用KV类型的缓存接口及内存版的基本实现 在不改变接口调用的情况下,可实现其他如 redis 的缓存支持
Index ¶
Constants ¶
View Source
const ( // OPTIONS_DEFAULT_EXPIRES_NAME 默认过期时间配置名称,值类型为 time.Duration OPTIONS_DEFAULT_EXPIRES_NAME = `expires` // OPTIONS_DEFAULT_CAPACITY_NAME 默认缓存集合大小,值类型为 int OPTIONS_DEFAULT_CAPACITY_NAME = `capacity` )
View Source
const (
// DEFAULT_CAPACITY 默认缓存集合大小
DEFAULT_CAPACITY = 1000
)
Variables ¶
View Source
var ( ErrKeyNotExists = errors.New(`key does not exist in the cache`) ErrKeyExpired = errors.New(`cache has expired`) )
View Source
var DEFAULT_EXPIRES = time.Minute * 40
DEFAULT_EXPIRES 默认过期时间
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Open 打开Cache服务
Open() error
// Close 关闭Cache服务
Close() error
// Set 设置指定kv到缓存中,如存在key则覆盖
Set(key string, value interface{}, expires ...time.Duration)
// Get 获取指定key的value值
Get(key string) (interface{}, error)
// Exists 查询缓存中是否存在指定key
Exists(key string) bool
// Expires 设置某个key的超时设置
Expires(key string, expires time.Duration)
// Delete 从缓存中移除某个key
Delete(key string)
// Keys 返回缓存中的所有key
Keys() []string
// Size 返回缓存大小
Size() int
}
Cache �KV型缓存通用接口
func NewBuiltinCache ¶
NewBuiltinCache 初始化一个内建内存型缓存
Click to show internal directories.
Click to hide internal directories.