Documentation
¶
Index ¶
- Constants
- Variables
- type CacheInterface
- type GRedis
- func (gr *GRedis) Add(key string, value interface{}, ttl time.Duration) (err error)
- func (gr *GRedis) AddNX(key string, value interface{}, ttl time.Duration) bool
- func (gr *GRedis) Delete(key string) error
- func (gr *GRedis) Flush() error
- func (gr *GRedis) Get(key string, defaultValue interface{}) (ptrValue interface{}, err error)
- func (gr *GRedis) GetMulti(keys ...string) (object.HashMap, error)
- func (gr *GRedis) GetSeconds(ttl time.Duration) int
- func (gr *GRedis) Has(key string) bool
- func (gr *GRedis) Invalidate(tags []string)
- func (gr *GRedis) Keys() ([]string, error)
- func (gr *GRedis) Put(key interface{}, value interface{}, ttl time.Duration) bool
- func (gr *GRedis) PutMany(values object.Array, ttl time.Duration) bool
- func (gr *GRedis) PutManyForever(values []interface{}) bool
- func (gr *GRedis) Remember(key string, ttl time.Duration, callback func() (interface{}, error)) (obj interface{}, err error)
- func (gr *GRedis) Set(key string, value interface{}, expires time.Duration) error
- func (gr *GRedis) SetByTags(key string, val interface{}, tags []string, expiry time.Duration) error
- func (gr *GRedis) SetEx(key string, value interface{}, expires time.Duration) error
- type MemCache
- func (cache *MemCache) Add(key string, value interface{}, ttl time.Duration) (err error)
- func (cache *MemCache) AddNX(key string, value interface{}, ttl time.Duration) bool
- func (cache *MemCache) Get(key string, defaultValue interface{}) (returnValue interface{}, err error)
- func (cache *MemCache) Has(key string) bool
- func (cache *MemCache) Remember(key string, ttl time.Duration, callback func() (interface{}, error)) (obj interface{}, err error)
- func (cache *MemCache) Set(key string, value interface{}, expires time.Duration) error
Constants ¶
View Source
const DEFAULT_EXPIRES_IN = 5
View Source
const DEFAULT_PURGE_EXPIRES_IN_PERIOD = 10
View Source
const SCRIPT_SETEX = `return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])`
View Source
const SYSTEM_CACHE_TIMEOUT = 60 * 60
View Source
const SYSTEM_CACHE_TIMEOUT_DAY = 60 * 60 * 24
View Source
const SYSTEM_CACHE_TIMEOUT_HOUR = 60 * 60
View Source
const SYSTEM_CACHE_TIMEOUT_MINUTE = 60
View Source
const SYSTEM_CACHE_TIMEOUT_MONTH = 60 * 60 * 24 * 30
View Source
const SYSTEM_CACHE_TIMEOUT_SEASON = 60 * 60 * 24 * 30 * 3
View Source
const SYSTEM_CACHE_TIMEOUT_YEAR = 60 * 60 * 24 * 30 * 3 * 12
Variables ¶
View Source
var ( ErrCacheMiss = errors.New("cache: miss") ErrCASConflict = errors.New("cache: compare-and-swap conflict") ErrNoStats = errors.New("cache: no statistics available") ErrNotStored = errors.New("cache: item not stored") ErrServerError = errors.New("cache: server error") ErrInvalidValue = errors.New("cache: invalid value") )
View Source
var CTXRedis = context.Background()
Functions ¶
This section is empty.
Types ¶
type CacheInterface ¶
type CacheInterface interface {
//SetOptions(opts interface{}) error
//
///**
//* Fetches a value from the cache.
//*
//* @param string key The unique key of this item in the cache.
//* @param mixed default Default value to return if the key does not exist.
//*
//* @return mixed The value of the item from the cache, or default in case of cache miss.
//*
//* @panic InvalidArgumentException
//* MUST be thrown if the key string,is not a legal value.
//*/
Get(key string, defaultValue interface{}) (ptrValue interface{}, err error)
//
///**
//* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
//*
//* @param string key The key of the item to store.
//* @param mixed value The value of the item to store, must be serializable.
//* @param null|int|\DateInterval ttl Optional. The TTL value of this item. If no value is sent and
//* the driver supports TTL then the library may set a default value
//* for it or let the driver take care of that.
//*
//* @return bool True on success and false on failure.
//*
//* @panic InvalidArgumentException
//* MUST be thrown if the key string,is not a legal value.
//*/
Set(key string, value interface{}, expires time.Duration) error
//
///**
//* Delete an item from the cache by its unique key.
//*
//* @param string key The unique cache key of the item to delete.
//*
//* @return bool True if the item was successfully removed. False if there was an error.
//*
//* @panic InvalidArgumentException
//* MUST be thrown if the key string,is not a legal value.
//*/
//Delete(key string) bool
//
///**
//* Wipes clean the entire cache's keys.
//*
//* @return bool True on success and false on failure.
//*/
//Clear() bool
//
///**
//* Obtains multiple cache items by their unique keys.
//*
//* @param iterable keys A list of keys that can obtained in a single operation.
//* @param mixed default Default value to return for keys that do not exist.
//*
//* @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have default as value.
//*
//* @panic InvalidArgumentException
//* MUST be thrown if keys is neither an array nor a Traversable,
//* or if any of the keys are not a legal value.
//*/
//GetMultiple(keys string, defaultValue object.HashMap) interface{}
//
///**
//* Persists a set of key => value pairs in the cache, with an optional TTL.
//*
//* @param iterable values A list of key => value pairs for a multiple-set operation.
//* @param null|int|\DateInterval ttl Optional. The TTL value of this item. If no value is sent and
//* the driver supports TTL then the library may set a default value
//* for it or let the driver take care of that.
//*
//* @return bool True on success and false on failure.
//*
//* @panic InvalidArgumentException
//* MUST be thrown if values is neither an array nor a Traversable,
//* or if any of the values are not a legal value.
//*/
//SetMultiple(values string, ttl int) bool
//
///**
//* Deletes multiple cache items in a single operation.
//*
//* @param iterable keys A list of string-based keys to be deleted.
//*
//* @return bool True if the items were successfully removed. False if there was an error.
//*
//* @panic InvalidArgumentException
//* MUST be thrown if keys is neither an array nor a Traversable,
//* or if any of the keys are not a legal value.
//*/
//DeleteMultiple(keys []string) bool
//
///**
//* Determines whether an item is present in the cache.
//*
//* NOTE: It is recommended that has() is only to be used for cache warming type purposes
//* and not to be used within your live applications operations for get/set, as this method
//* is subject to a race condition where your has() will return true and immediately after,
//* another script can remove it making the state of your app out of date.
//*
//* @param string key The cache item key.
//*
//* @return bool
//*
//* @panic InvalidArgumentException
//* MUST be thrown if the key string,is not a legal value.
//*/
Has(key string) bool
AddNX(key string, value interface{}, ttl time.Duration) bool
///**
//* Store an item in the cache if the key does not exist.
//*
//* @param string key
//* @param mixed value
//* @param \DateTimeInterface|\DateInterval|int|null ttl
//* @return bool
//*/
Add(key string, value interface{}, ttl time.Duration) (err error)
//
///**
//* Increment the value of an item in the cache.
//*
//* @param string key
//* @param mixed value
//* @return int|bool
//*/
//Increment(key string, value object.HashMap)(int, bool)
//
///**
//* Decrement the value of an item in the cache.
//*
//* @param string key
//* @param mixed value
//* @return int|bool
//*/
//Decrement(key string, value object.HashMap) (int, bool)
//
///**
//* Store an item in the cache indefinitely.
//*
//* @param string key
//* @param mixed value
//* @return bool
//*/
//Forever(key string, value object.HashMap) bool
//
///**
//* Get an item from the cache, or execute the given Closure and store the result.
//*
//* @param string key
//* @param \DateTimeInterface|\DateInterval|int|null ttl
//* @param \Closure callback
//* @return mixed
//*/
Remember(key string, ttl time.Duration, callback func() (interface{}, error)) (obj interface{}, err error)
}
var ACCache CacheInterface
func NewMemCache ¶
func NewMemCache(namespace string, defaultLifeTime time.Duration, directory string) CacheInterface
type GRedis ¶
type GRedis struct {
Pool redis.UniversalClient
// contains filtered or unexported fields
}
func NewGRedis ¶
func NewGRedis(opts *redis.UniversalOptions) (gr *GRedis)
func (*GRedis) GetSeconds ¶
*
- Calculate the number of seconds for the given TTL. *
- @param \DateTimeInterface|\DateInterval|int ttl
- @return int
func (*GRedis) Invalidate ¶
func (*GRedis) Put ¶
*
- Store an item in the cache. *
- @param string key
- @param mixed value
- @param \DateTimeInterface|\DateInterval|int|null ttl
- @return bool
func (*GRedis) PutMany ¶
*
- Store multiple items in the cache for a given number of seconds. *
- @param array values
- @param \DateTimeInterface|\DateInterval|int|null ttl
- @return bool
func (*GRedis) PutManyForever ¶
*
- Store multiple items in the cache indefinitely. *
- @param array values
- @return bool
func (*GRedis) Remember ¶
func (gr *GRedis) Remember(key string, ttl time.Duration, callback func() (interface{}, error)) (obj interface{}, err error)
*
- Get an item from the cache, or execute the given Closure and store the result. *
- @param string key
- @param \DateTimeInterface|\DateInterval|int|null ttl
- @param \Closure callback
- @return mixed
Click to show internal directories.
Click to hide internal directories.