Documentation ¶
Index ¶
Constants ¶
View Source
const ( // TypeGoCache - type go cache TypeGoCache = "goCache" // TypeMemoryCache - type use memcached TypeMemoryCache = "memCache" // TypeRedisCache - type use redis TypeRedisCache = "redisCache" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache interface { // get cached value by key. Get(key string) interface{} // GetMulti is a batch version of Get. GetMulti(keys []string) []interface{} // set cached value with key and expire time. Put(key string, val interface{}, timeout time.Duration) error // delete cached value by key. Delete(key string) error // increase cached int value by key, as a counter. Incr(key string) error // decrease cached int value by key, as a counter. Decr(key string) error // increase cached int value by key and return value. IncrBy(key string) (interface{}, error) // decrease cached int value by key and return value. DecrBy(key string) (interface{}, error) // lock key with timeout TryLock(key string, val interface{}, timeout time.Duration) error // unlock key UnLock(key string, val interface{}) error // set key Set(key string, val interface{}) (bool, error) // expire key with timeout Expire(key string, timeout time.Duration) error // check if cached value exists or not. IsExist(key string) bool // clear all cache. ClearAll() error // start gc routine based on config settings. StartAndGC(config Config) error }
Cache interface contains all behaviors for cache adapter.
type Config ¶
type Config struct { Expiration time.Duration `json:"expiration"` // public common Server string `json:"server"` User string `json:"user"` Password string `json:"password"` Port int64 `json:"port"` // redis DBNum int64 `json:"db_num"` MaxIdle int64 `json:"max_idle"` MaxActive int64 `json:"max_active"` Key string `json:"key"` // Extend fields // Extended fields can be used if there is a special implementation Extend1 string `json:"extend_1"` Extend2 string `json:"extend_2"` }
Config - define cache config
Click to show internal directories.
Click to hide internal directories.