Documentation ¶
Index ¶
- Variables
- type Cache
- type Config
- type Disk
- type Keys
- type MemCache
- func (mem *MemCache) AutoCleanExpireKey(interval time.Duration)
- func (mem *MemCache) Close()
- func (mem *MemCache) Delete(key string)
- func (mem *MemCache) FlushAll()
- func (mem *MemCache) Get(key string) (value interface{}, ok bool)
- func (mem *MemCache) GetWithExpire(key string) (value interface{}, ttl int64, ok bool)
- func (mem *MemCache) GobRegister(v ...interface{})
- func (mem *MemCache) Keys(prefix string) Keys
- func (mem *MemCache) LoadFromDisk() error
- func (mem *MemCache) Set(key string, value interface{}) error
- func (mem *MemCache) SetWithExpire(key string, value interface{}, ttl int64) error
- func (mem *MemCache) Size() int64
- func (mem *MemCache) WriteToDisk() error
- type RWMap
- func (s *RWMap) Delete(key string)
- func (s *RWMap) Exists(key string) bool
- func (s *RWMap) Flush()
- func (s *RWMap) Load(key string) (value interface{}, ok bool)
- func (s *RWMap) LoadOrStore(key string, value interface{}) (actual interface{}, loaded bool)
- func (s *RWMap) Range(f func(k string, v interface{}) bool)
- func (s *RWMap) Size() int64
- func (s *RWMap) Store(key string, value interface{})
- type Store
- type SyncMap
- func (s *SyncMap) Delete(key string)
- func (s *SyncMap) Exists(key string) bool
- func (s *SyncMap) Flush()
- func (s *SyncMap) Load(key string) (value interface{}, ok bool)
- func (s *SyncMap) LoadOrStore(key string, value interface{}) (actual interface{}, loaded bool)
- func (s *SyncMap) Range(fn func(k string, v interface{}) bool)
- func (s *SyncMap) Size() int64
- func (s *SyncMap) Store(key string, value interface{})
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrKeysOverLimitSize = errors.New("keys over limit size")
)
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { Get(key string) (value interface{}, exists bool) // GetWithExpire(key string) (value interface{}, ttl int64, exists bool) // 返回值和剩余时间 Set(key string, value interface{}) error // SetWithExpire(key string, value interface{}, ttl int64) error // ttl 秒级别 Keys(prefix string) Keys // prefix - 前缀查询,"" 查询所有, 只返回当前有效的key Delete(key string) // Size() int64 // 当前存储的数据量 FlushAll() // 删除所有 key GobRegister(v ...interface{}) // 注册自定义结构体 WriteToDisk() error // 写入数据到磁盘, 如果存在自定义结构类型,在使用时 一定要先注册结构 LoadFromDisk() error // 从磁盘加载数据 Close() // }
type Disk ¶ added in v0.3.0
type Disk struct {
// contains filtered or unexported fields
}
func (*Disk) ReadFromFile ¶ added in v0.3.0
ReadFromFile 从文件读取数据
func (*Disk) WriteToFile ¶ added in v0.3.0
WriteToFile 写数据到文件 如果之前文件存在,则删除
type MemCache ¶ added in v0.3.0
type MemCache struct {
// contains filtered or unexported fields
}
MemCache
func NewMemCache ¶ added in v0.3.0
func NewMemCacheWithConfig ¶ added in v0.3.0
func NewRWMapCache ¶ added in v0.3.0
func NewRWMapCache() *MemCache
func NewRWMapCacheWithConfig ¶ added in v0.3.0
func NewSyncMapCache ¶ added in v0.3.0
func NewSyncMapCache() *MemCache
func NewSyncMapCacheWithConfig ¶ added in v0.3.0
func (*MemCache) AutoCleanExpireKey ¶ added in v0.3.0
AutoCleanExpireKey 自动在一定时间内清理过期 key 当设置了大量的 expire key 且通常只读取一次的情况下再建议使用。 interval 建议设置大一点,否则可能影响写入性能,建议设置 5-10 minute
func (*MemCache) GetWithExpire ¶ added in v0.3.0
func (*MemCache) GobRegister ¶ added in v0.3.0
func (mem *MemCache) GobRegister(v ...interface{})
GobRegister 注册自定义结构
func (*MemCache) LoadFromDisk ¶ added in v0.3.0
LoadFromDisk 从磁盘中读取缓存内容,过过滤掉已经过期的内容
func (*MemCache) SetWithExpire ¶ added in v0.3.0
SetWithExpire ttl - 过期时间秒级别, -1 永久有效
func (*MemCache) WriteToDisk ¶ added in v0.3.0
WriteToDisk 缓存内容写入磁盘,当缓存内容比较大时,不建议写入磁盘,比较耗费时间
type RWMap ¶ added in v0.3.0
type RWMap struct {
// contains filtered or unexported fields
}
RWMap 读写Map 当数据竞争不强,或读取多时。使用节省空间更快
func (*RWMap) LoadOrStore ¶ added in v0.3.0
type SyncMap ¶ added in v0.3.0
type SyncMap struct {
// contains filtered or unexported fields
}
SyncMap 并发Map 当数据竞争大时,多核CPU时,使用比RwMap性能好,缺点空间占用会多点
func NewSyncMap ¶ added in v0.3.0
func NewSyncMap() *SyncMap
func (*SyncMap) LoadOrStore ¶ added in v0.3.0
Click to show internal directories.
Click to hide internal directories.