Documentation
¶
Index ¶
- Constants
- type Cache
- func (c *Cache) Add(key interface{}, value interface{}, expire time.Duration) error
- func (c *Cache) Close() error
- func (c *Cache) Delete(key interface{})
- func (c *Cache) Flush()
- func (c *Cache) Get(key interface{}) (value interface{}, ok bool)
- func (c *Cache) GetWithExpire(key interface{}) (interface{}, time.Duration, bool)
- func (c *Cache) LoadDisk(filename string) error
- func (c *Cache) Range(f func(key, value interface{}) bool)
- func (c *Cache) SaveDisk(filename string, mode saveMode) error
- func (c *Cache) Set(key interface{}, value interface{}) error
- func (c *Cache) SetExpire(key interface{}, value interface{}, expire time.Duration) error
- func (c *Cache) Size() int64
- type Config
Constants ¶
View Source
const ( // 超出容量报错 NoEvictionMode cleanMode = iota // 随机删除 keys 的某一 key AllKeysRandomMode // 随机删除 设置过期时间中keys de某一 key VolatileRandomMode )
超过 maxSize 清除策略
View Source
const ( // 保存所有的 keys value SaveAllKeysMode saveMode = iota // 只保存设置过期时间的 keys value SaveExpireKeysMode // 只保存永久 keys value SaveNoExpireKeysMode )
存储规则
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache Cache
func (*Cache) GetWithExpire ¶
GetWithExpire 返回 key 剩余时间
type Config ¶
type Config struct {
// 超过容量限制自动清除 keys 方式
OverSizeClearMode cleanMode
// keys 容量限制,通过此预估内存使用量
MaxSize int64
// 定时清除过期的 key, 未设置,则不清除
CleanInterval time.Duration
// 自动保存缓存内容到文件
AutoSave bool
// 保存的内容类型
SaveType saveMode
// 保存到文件名, 绝对路径 eg: /tmp/cache.back
Filename string
}
Config 配置选项说明
Click to show internal directories.
Click to hide internal directories.