Documentation ¶
Overview ¶
*
*Created by Xie Jian on 2019/10/14 9:42
*
*Created by Xie Jian on 2019/10/14 10:07
Index ¶
- Variables
- func GetBool(v interface{}) bool
- func GetFloat64(v interface{}) float64
- func GetInt(v interface{}) int
- func GetInt64(v interface{}) int64
- func GetString(v interface{}) string
- func GobDecode(data []byte, to *FileCacheItem) error
- func GobEncode(data interface{}) ([]byte, error)
- func Register(adapterName CacheAdapterName, adapter CacheInstance)
- type Cache
- type CacheAdapterName
- type CacheInstance
- type FileCache
- func (fc *FileCache) ClearAll() error
- func (fc *FileCache) Delete(key string) error
- func (fc *FileCache) Get(key string) interface{}
- func (fc *FileCache) GetMulti(keys []string) []interface{}
- func (fc *FileCache) IsExist(key string) bool
- func (fc *FileCache) Put(key string, val interface{}, timeout time.Duration) error
- func (fc *FileCache) StartCache(config string) error
- type FileCacheItem
- type MemoryCache
- func (mc *MemoryCache) ClearAll() error
- func (mc *MemoryCache) Delete(key string) error
- func (mc *MemoryCache) Get(key string) interface{}
- func (mc *MemoryCache) GetMulti(keys []string) []interface{}
- func (mc *MemoryCache) IsExist(key string) bool
- func (mc *MemoryCache) Put(key string, value interface{}, lifeSpan time.Duration) error
- func (mc *MemoryCache) StartCache(config string) error
- type MemoryItem
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // 缓存目录 FileCachePath = "cache" // 缓存文件后缀 FileCacheFileSuffix = ".bin" // 如果自动生成缓存文件,缓存文件的目录深度 FileCacheDirectoryLevel = 2 // 缓存文件的过期时间,默认不过期 FileCacheEmbedExpiry time.Duration )
文件缓存
View Source
var DefaultValidTimeout = 60 // 1分钟
默认过期校验时间
Functions ¶
func GetFloat64 ¶
func GetFloat64(v interface{}) float64
Types ¶
type Cache ¶
type Cache interface { // 通过key获取cache存储的值 Get(key string) interface{} // 获取所有值 GetMulti(keys []string) []interface{} // 存储key并设置过期时间 Put(key string, val interface{}, timeout time.Duration) error // 删除key Delete(key string) error // 校验key是否存在 IsExist(key string) bool // 清空 ClearAll() error // 注册绑定方式 StartCache(config string) error }
type CacheAdapterName ¶
type CacheAdapterName string
const ( CacheRedisAdapter CacheAdapterName = "redis" CacheMemcacheAdapter CacheAdapterName = "memcache" CacheFileAdapter CacheAdapterName = "file" CacheMemoryAdapter CacheAdapterName = "memory" )
type FileCache ¶
type FileCache struct { CachePath string `json:"cachePath"` FileSuffix string `json:"fileSuffix"` DirectoryLevel int `json:"directoryLevel"` EmbedExpired int64 `json:"embedExpired"` // 过期时间 }
FileCache 文件缓存适配器
func (*FileCache) StartCache ¶
StartCache 调用文件缓存 config:{"cachePath":"/cache","fileSuffix":".log","directoryLevel":2,"embedExpired":0}
type FileCacheItem ¶
type FileCacheItem struct { Data interface{} `json:"data"` LastAccess time.Time `json:"lastAccess"` Expired time.Time `json:"expired"` }
FileCacheItem 存储元
type MemoryCache ¶
MemoryCache 内存适配器,用读写锁保证map的读写安全
func (*MemoryCache) Get ¶
func (mc *MemoryCache) Get(key string) interface{}
Get 从内存获取值,如果不存在或过期返回nil
func (*MemoryCache) GetMulti ¶
func (mc *MemoryCache) GetMulti(keys []string) []interface{}
GetAll 返回所有key:value,不包含其他内容
func (*MemoryCache) Put ¶
func (mc *MemoryCache) Put(key string, value interface{}, lifeSpan time.Duration) error
Put 存放key:value,lifeSpan设置过期时间,如果设为0,表示永远存在不会被删除
func (*MemoryCache) StartCache ¶
func (mc *MemoryCache) StartCache(config string) error
StartCache 调用memory config: {"interval":60}
type MemoryItem ¶
type MemoryItem struct {
// contains filtered or unexported fields
}
MemoryItem 存储元
Click to show internal directories.
Click to hide internal directories.