Documentation ¶
Index ¶
- Constants
- Variables
- 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
- type Entry
- type FreeCache
- type G2Cache
- type Harsher
- type HitStatistics
- type Job
- type LoadDataSourceFunc
- type LocalCache
- type LoggerInterface
- type OutCache
- type Pool
- type PubSub
- type RedisCache
- 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
Constants ¶
View Source
const ( SetPublishType int8 = iota DelPublishType )
Entry expire is UnixNano
Variables ¶
View Source
var ( CacheDebug bool CacheMonitor bool OutCachePubSub bool CacheMonitorSecond = 5 DefaultGPoolWorkerNum = 200 DefaultGPoolJobQueueChanLen = 1000 )
View Source
var ( CacheKeyEmpty = errors.New("cache key is empty") CacheObjNil = errors.New("cache object is nil") LoadDataSourceFuncNil = errors.New("cache load func is nil") LocalStorageClose = errors.New("local storage close !!! ") OutStorageClose = errors.New("out storage close !!! ") CacheClose = errors.New("g2cache close !!! ") DataSourceLoadNil = errors.New("data source load nil") OutStorageLoadNil = errors.New("out storage load nil") CacheNotImplementPubSub = errors.New("cache not implement pubsub interface") )
View Source
var (
DefaultFreeCacheSize = 50 * 1024 * 1024 // 50MB
)
View Source
var DefaultPubSubRedisChannel = "g2cache-pubsub-channel"
View Source
var (
EntryLazyFactor = 32
)
Functions ¶
Types ¶
type ChannelMeta ¶
type Entry ¶
type Entry struct { Value interface{} `json:"value"` TtlSecond int `json:"ttl"` Obsolete int64 `json:"obsolete"` Expiration int64 `json:"expiration"` }
func (*Entry) Expired ¶
Expired means that the data is unavailable and data needs to be synchronized
func (*Entry) GetExpireTTL ¶
func (*Entry) GetObsoleteTTL ¶
type FreeCache ¶
type FreeCache struct {
// contains filtered or unexported fields
}
func NewFreeCache ¶
func NewFreeCache() *FreeCache
func (*FreeCache) ThreadSafe ¶
func (c *FreeCache) ThreadSafe()
type G2Cache ¶
type G2Cache struct { GID string // Identifies the number of an instance // contains filtered or unexported fields }
type HitStatistics ¶
type HitStatistics struct { HitOutStorageTotalRate float64 `json:"hit_out_storage_total_rate"` HitDataSourceTotalRate float64 `json:"hit_data_source_total_rate"` HitLocalStorageTotalRate float64 `json:"hit_local_storage_total_rate"` HitDataSourceTotal int64 `json:"hit_data_source_total"` HitLocalStorageTotal int64 `json:"hit_local_storage_total"` HitOutStorageTotal int64 `json:"hit_out_storage_total"` AccessGetTotal int64 `json:"access_get_total"` }
var HitStatisticsOut HitStatistics
func (*HitStatistics) Calculation ¶
func (h *HitStatistics) Calculation()
func (*HitStatistics) StatisticsDataSource ¶
func (h *HitStatistics) StatisticsDataSource()
func (*HitStatistics) StatisticsLocalStorage ¶
func (h *HitStatistics) StatisticsLocalStorage()
func (*HitStatistics) StatisticsOutStorage ¶
func (h *HitStatistics) StatisticsOutStorage()
func (*HitStatistics) String ¶
func (h *HitStatistics) String() string
type Job ¶
type Job func()
Represents user request, function which should be executed in some worker.
type LoadDataSourceFunc ¶
type LoadDataSourceFunc func() (interface{}, error)
Shouldn't throw a panic, please return an error
type LocalCache ¶
type LocalCache interface { Get(key string, obj interface{}) (*Entry, bool, error) // obj represents the internal structure of the real object Set(key string, e *Entry) error // local storage should set Entry.Obsolete Del(key string) error ThreadSafe() // Need to ensure thread safety Close() }
Local memory cache,Local memory cache with high access speed
type LoggerInterface ¶
type LoggerInterface interface { LogInfoF(f string, s ...interface{}) LogInfo(s ...interface{}) LogDebug(s ...interface{}) LogDebugF(f string, s ...interface{}) LogErr(s ...interface{}) LogErrF(f string, s ...interface{}) }
外部调用者可实现此日志接口用于将日志导出
var (
Logger LoggerInterface = &sysLogger{}
)
type OutCache ¶
type OutCache interface { Get(key string, obj interface{}) (*Entry, bool, error) // obj represents the internal structure of the real object Set(key string, e *Entry) error // out storage should set Entry.Expiration Del(key string) error ThreadSafe() // Need to ensure thread safety Close() }
External cache has faster access speed, such as Redis
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
type PubSub ¶
type PubSub interface { Subscribe(data chan<- *ChannelMeta) error Publish(gid, key string, action int8, data *Entry) error }
only out storage pub sub
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
func NewRedisCache ¶
func NewRedisCache() (*RedisCache, error)
func (*RedisCache) Close ¶
func (r *RedisCache) Close()
func (*RedisCache) Del ¶
func (r *RedisCache) Del(key string) error
func (*RedisCache) DistributedEnable ¶
func (r *RedisCache) DistributedEnable() bool
func (*RedisCache) Get ¶
func (r *RedisCache) Get(key string, obj interface{}) (*Entry, bool, error)
func (*RedisCache) Publish ¶
func (r *RedisCache) Publish(gid, key string, action int8, value *Entry) error
func (*RedisCache) Subscribe ¶
func (r *RedisCache) Subscribe(ch chan<- *ChannelMeta) error
func (*RedisCache) ThreadSafe ¶
func (r *RedisCache) ThreadSafe()
Source Files ¶
Click to show internal directories.
Click to hide internal directories.