Versions in this module Expand all Collapse all v1 v1.0.0 Dec 22, 2023 Changes in this version + const DelPublishType + const SetPublishType + var CacheClose = errors.New("g2cache close !!! ") + var CacheDebug bool + var CacheKeyEmpty = errors.New("cache key is empty") + var CacheMonitor bool + var CacheMonitorSecond = 5 + var CacheNotImplementPubSub = errors.New("cache not implement pubsub interface") + var CacheObjNil = errors.New("cache object is nil") + var DataSourceLoadNil = errors.New("data source load nil") + var DefaultFreeCacheSize = 50 * 1024 * 1024 + var DefaultGPoolJobQueueChanLen = 1000 + var DefaultGPoolWorkerNum = 200 + var DefaultPubSubRedisChannel = "g2cache-pubsub-channel" + var EntryLazyFactor = 32 + var LoadDataSourceFuncNil = errors.New("cache load func is nil") + var LocalStorageClose = errors.New("local storage close !!! ") + var OutCachePubSub bool + var OutStorageClose = errors.New("out storage close !!! ") + var OutStorageLoadNil = errors.New("out storage load nil") + func GenKey(args ...interface{}) string + func GetRedisPool(conf *RedisConf) (*redis.Pool, error) + func LogDebug(s ...interface{}) + func LogDebugF(f string, s ...interface{}) + func LogErr(s ...interface{}) + func LogErrF(f string, s ...interface{}) + func LogInfo(s ...interface{}) + func LogInfoF(f string, s ...interface{}) + func NewUUID() (string, error) + func RedisDelKey(key string, pool *redis.Pool) error + func RedisGetString(key string, pool *redis.Pool) (string, error) + func RedisPublish(channel, message string, pool *redis.Pool) error + func RedisSetString(key, value string, ttl int, pool *redis.Pool) error + type ChannelMeta struct + Action int8 + Data *Entry + Gid string + Key string + type Entry struct + Expiration int64 + Obsolete int64 + TtlSecond int + Value interface{} + func NewEntry(v interface{}, second int) *Entry + func (e *Entry) Expired() bool + func (e *Entry) GetExpireTTL() (second int64) + func (e *Entry) GetObsoleteTTL() (second int64) + func (e *Entry) Obsoleted() bool + func (e *Entry) String() string + type FreeCache struct + func NewFreeCache() *FreeCache + func (c *FreeCache) Close() + func (c *FreeCache) Del(key string) error + func (c *FreeCache) Get(key string, obj interface{}) (*Entry, bool, error) + func (c *FreeCache) Set(key string, e *Entry) error + func (c *FreeCache) ThreadSafe() + type G2Cache struct + GID string + func New(out OutCache, local LocalCache) (g *G2Cache, err error) + func (g *G2Cache) Close() + func (g *G2Cache) Del(key string, wait bool) (err error) + func (g *G2Cache) Get(key string, ttlSecond int, obj interface{}, fn LoadDataSourceFunc) error + func (g *G2Cache) Set(key string, obj interface{}, ttlSecond int, wait bool) (err error) + type Harsher interface + Sum64 func(string) uint64 + type HitStatistics struct + AccessGetTotal int64 + HitDataSourceTotal int64 + HitDataSourceTotalRate float64 + HitLocalStorageTotal int64 + HitLocalStorageTotalRate float64 + HitOutStorageTotal int64 + HitOutStorageTotalRate float64 + var HitStatisticsOut HitStatistics + func (h *HitStatistics) Calculation() + func (h *HitStatistics) StatisticsDataSource() + func (h *HitStatistics) StatisticsLocalStorage() + func (h *HitStatistics) StatisticsOutStorage() + func (h *HitStatistics) String() string + type Job func() + type LoadDataSourceFunc func() (interface{}, error) + type LocalCache interface + Close func() + Del func(key string) error + Get func(key string, obj interface{}) (*Entry, bool, error) + Set func(key string, e *Entry) error + ThreadSafe func() + type LoggerInterface interface + LogDebug func(s ...interface{}) + LogDebugF func(f string, s ...interface{}) + LogErr func(s ...interface{}) + LogErrF func(f string, s ...interface{}) + LogInfo func(s ...interface{}) + LogInfoF func(f string, s ...interface{}) + var Logger LoggerInterface = &sysLogger{} + type OutCache interface + Close func() + Del func(key string) error + Get func(key string, obj interface{}) (*Entry, bool, error) + Set func(key string, e *Entry) error + ThreadSafe func() + type Pool struct + func NewPool(numWorkers int, jobQueueLen int) *Pool + func (p *Pool) Release() + func (p *Pool) SendJob(job func()) + func (p *Pool) SendJobWithDeadline(job func(), t time.Time) bool + func (p *Pool) SendJobWithTimeout(job func(), t time.Duration) bool + type PubSub interface + Publish func(gid, key string, action int8, data *Entry) error + Subscribe func(data chan<- *ChannelMeta) error + type RedisCache struct + func NewRedisCache() (*RedisCache, error) + func (r *RedisCache) Close() + func (r *RedisCache) Del(key string) error + func (r *RedisCache) DistributedEnable() bool + func (r *RedisCache) Get(key string, obj interface{}) (*Entry, bool, error) + func (r *RedisCache) Publish(gid, key string, action int8, value *Entry) error + func (r *RedisCache) Set(key string, obj *Entry) error + func (r *RedisCache) Subscribe(ch chan<- *ChannelMeta) error + func (r *RedisCache) ThreadSafe() + type RedisConf struct + DB int + DSN string + MaxConn int + Pwd string + var DefaultPubSubRedisConf RedisConf + var DefaultRedisConf RedisConf