Documentation
¶
Index ¶
- Constants
- type CacheDb
- type CacheIns
- type CacheMemory
- type CacheRedis
- type HoTimeCache
- func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj
- func (that *HoTimeCache) CachesDelete(keys []string)
- func (that *HoTimeCache) CachesGet(keys []string) Map
- func (that *HoTimeCache) CachesSet(data Map)
- func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj
- func (that *HoTimeCache) DisableDbCache()
- func (that *HoTimeCache) Init(config Map, hotimeDb HoTimeDBInterface, logger *log.Logger)
- func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj
- func (that *HoTimeCache) SessionsDelete(keys []string)
- func (that *HoTimeCache) SessionsGet(keys []string) Map
- func (that *HoTimeCache) SessionsSet(data Map)
- type HoTimeDBInterface
Constants ¶
const ( CacheTableName = "hotime_cache" CacheHistoryTableName = "hotime_cache_history" LegacyCacheTableName = "cached" // 老版本缓存表名 DefaultCacheTimeout = 24 * 60 * 60 // 默认过期时间 24 小时 CacheModeNew = "new" // 新模式:只使用新表 CacheModeCompatible = "compatible" // 兼容模式:写新读老 )
表名常量
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheDb ¶
type CacheDb struct {
TimeOut int64
DbSet bool
SessionSet bool
HistorySet bool // 是否开启历史记录
Mode string // 缓存模式:"new"(默认,只用新表) 或 "compatible"(写新读老)
Db HoTimeDBInterface
Log *log.Logger
ContextBase
// contains filtered or unexported fields
}
func (*CacheDb) Cache ¶
Cache 缓存操作入口 用法:
- Cache(key) - 获取缓存
- Cache(key, value) - 设置缓存(使用默认过期时间)
- Cache(key, value, timeout) - 设置缓存(指定过期时间,单位:秒)
- Cache(key, nil) - 删除缓存
func (*CacheDb) CachesDelete ¶ added in v1.6.6
CachesDelete 批量删除缓存
type CacheMemory ¶
type CacheMemory struct {
TimeOut int64
DbSet bool
SessionSet bool
Log *log.Logger
// contains filtered or unexported fields
}
CacheMemory 基于 sync.Map 的缓存实现
func (*CacheMemory) Cache ¶
func (c *CacheMemory) Cache(key string, data ...interface{}) *Obj
func (*CacheMemory) CachesDelete ¶ added in v1.6.6
func (c *CacheMemory) CachesDelete(keys []string)
CachesDelete 批量删除缓存
func (*CacheMemory) CachesGet ¶ added in v1.6.6
func (c *CacheMemory) CachesGet(keys []string) Map
CachesGet 批量获取缓存 返回 Map,key 为缓存键,value 为缓存值(不存在或过期的 key 不包含在结果中)
func (*CacheMemory) CachesSet ¶ added in v1.6.6
func (c *CacheMemory) CachesSet(data Map, timeout ...int64)
CachesSet 批量设置缓存 data: Map,key 为缓存键,value 为缓存值 timeout: 可选过期时间(秒),不传则使用默认超时时间
type CacheRedis ¶
type CacheRedis struct {
TimeOut int64
DbSet bool
SessionSet bool
Host string
Pwd string
Port int64
ContextBase
Log *log.Logger
// contains filtered or unexported fields
}
func (*CacheRedis) Cache ¶
func (that *CacheRedis) Cache(key string, data ...interface{}) *Obj
func (*CacheRedis) CachesDelete ¶ added in v1.6.6
func (that *CacheRedis) CachesDelete(keys []string)
CachesDelete 批量删除缓存(使用 Redis DEL 命令批量删除)
func (*CacheRedis) CachesGet ¶ added in v1.6.6
func (that *CacheRedis) CachesGet(keys []string) Map
CachesGet 批量获取缓存(使用 Redis MGET 命令优化) 返回 Map,key 为缓存键,value 为缓存值(不存在的 key 不包含在结果中)
func (*CacheRedis) CachesSet ¶ added in v1.6.6
func (that *CacheRedis) CachesSet(data Map, timeout ...int64)
CachesSet 批量设置缓存(使用 Redis pipeline 优化) data: Map,key 为缓存键,value 为缓存值 timeout: 可选过期时间(秒),不传则使用默认超时时间
type HoTimeCache ¶
HoTimeCache 可配置memory,db,redis,默认启用memory,默认优先级为memory>redis>db,memory与数据库缓存设置项一致, 缓存数据填充会自动反方向反哺,加入memory缓存过期将自动从redis更新,但memory永远不会更新redis,如果是集群建议不要开启memory,配置即启用
func (*HoTimeCache) Cache ¶
func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj
func (*HoTimeCache) CachesDelete ¶ added in v1.6.6
func (that *HoTimeCache) CachesDelete(keys []string)
CachesDelete 批量删除普通缓存
func (*HoTimeCache) CachesGet ¶ added in v1.6.6
func (that *HoTimeCache) CachesGet(keys []string) Map
CachesGet 批量获取普通缓存 返回 Map,key 为缓存键,value 为缓存值 优先级:memory > redis > db,低优先级数据会反哺到高优先级缓存
func (*HoTimeCache) CachesSet ¶ added in v1.6.6
func (that *HoTimeCache) CachesSet(data Map)
CachesSet 批量设置普通缓存 data: Map,key 为缓存键,value 为缓存值
func (*HoTimeCache) Db ¶
func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj
func (*HoTimeCache) DisableDbCache ¶ added in v1.6.7
func (that *HoTimeCache) DisableDbCache()
func (*HoTimeCache) Init ¶
func (that *HoTimeCache) Init(config Map, hotimeDb HoTimeDBInterface, logger *log.Logger)
func (*HoTimeCache) Session ¶
func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj
func (*HoTimeCache) SessionsDelete ¶ added in v1.6.6
func (that *HoTimeCache) SessionsDelete(keys []string)
SessionsDelete 批量删除 Session 缓存
func (*HoTimeCache) SessionsGet ¶ added in v1.6.6
func (that *HoTimeCache) SessionsGet(keys []string) Map
SessionsGet 批量获取 Session 缓存 返回 Map,key 为缓存键,value 为缓存值 优先级:memory > redis > db,低优先级数据会反哺到高优先级缓存
func (*HoTimeCache) SessionsSet ¶ added in v1.6.6
func (that *HoTimeCache) SessionsSet(data Map)
SessionsSet 批量设置 Session 缓存 data: Map,key 为缓存键,value 为缓存值
type HoTimeDBInterface ¶
type HoTimeDBInterface interface {
GetPrefix() string
Query(query string, args ...interface{}) []Map
Exec(query string, args ...interface{}) (sql.Result, error)
Get(table string, qu ...interface{}) Map
Select(table string, qu ...interface{}) []Map
Delete(table string, data map[string]interface{}) int64
Update(table string, data Map, where Map) int64
Insert(table string, data map[string]interface{}) int64
GetType() string
}