Documentation ¶
Index ¶
- Constants
- Variables
- func GetCacheType() string
- func InitCache() error
- func NewSessionKey() (error, string)
- func SessionGet(token string) (err error, userId string)
- func SessionSet(token, userId string, expires bool) error
- type CacheStore
- type InMemoryStore
- func (c *InMemoryStore) Add(key string, value interface{}, expires time.Duration) error
- func (c *InMemoryStore) Decrement(key string, n int64) (int64, error)
- func (c *InMemoryStore) Delete(key string) error
- func (c *InMemoryStore) Expire(key string, expires time.Duration) (bool, error)
- func (c *InMemoryStore) Flush() error
- func (c *InMemoryStore) Get(key string, value interface{}) error
- func (c *InMemoryStore) Increment(key string, n int64) (int64, error)
- func (c *InMemoryStore) Replace(key string, value interface{}, expires time.Duration) error
- func (c *InMemoryStore) Set(key string, value interface{}, expires time.Duration) error
- type RedisStore
- func (c *RedisStore) Add(key string, value interface{}, expires time.Duration) error
- func (c *RedisStore) Decrement(key string, delta int64) (newValue int64, err error)
- func (c *RedisStore) Delete(key string) error
- func (c *RedisStore) Expire(key string, expires time.Duration) (bool, error)
- func (c *RedisStore) Flush() error
- func (c *RedisStore) Get(key string, ptrValue interface{}) error
- func (c *RedisStore) Increment(key string, delta int64) (int64, error)
- func (c *RedisStore) Replace(key string, value interface{}, expires time.Duration) error
- func (c *RedisStore) Set(key string, value interface{}, expires time.Duration) error
Constants ¶
View Source
const ( DEFAULT = time.Duration(0) FOREVER = time.Duration(-1) )
Variables ¶
Functions ¶
func GetCacheType ¶
func GetCacheType() string
func NewSessionKey ¶
func SessionGet ¶
func SessionSet ¶
Types ¶
type CacheStore ¶
type CacheStore interface { // Get retrieves an item from the cache. Returns the item or nil, and a bool indicating // whether the key was found. Get(key string, value interface{}) error // Set sets an item to the cache, replacing any existing item. Set(key string, value interface{}, expire time.Duration) error // Add adds an item to the cache only if an item doesn't already exist for the given // key, or if the existing item has expired. Returns an error otherwise. Add(key string, value interface{}, expire time.Duration) error // Replace sets a new value for the cache key only if it already exists. Returns an // error if it does not. Replace(key string, data interface{}, expire time.Duration) error // Delete removes an item from the cache. Does nothing if the key is not in the cache. Delete(key string) error // Increment increments a real number, and returns error if the value is not real Increment(key string, data int64) (int64, error) // Decrement decrements a real number, and returns error if the value is not real Decrement(key string, data int64) (int64, error) // Flush seletes all items from the cache. Flush() error // Expire a key Expire(key string, expire time.Duration) (bool, error) }
CacheStore is the interface of a cache backend
func GetCache ¶
func GetCache() CacheStore
type InMemoryStore ¶
type InMemoryStore struct {
cache.Cache
}
InMemoryStore represents the cache with memory persistence
func NewInMemoryStore ¶
func NewInMemoryStore(defaultExpiration time.Duration) *InMemoryStore
NewInMemoryStore returns a InMemoryStore
func (*InMemoryStore) Add ¶
func (c *InMemoryStore) Add(key string, value interface{}, expires time.Duration) error
Add (see CacheStore interface)
func (*InMemoryStore) Decrement ¶
func (c *InMemoryStore) Decrement(key string, n int64) (int64, error)
Decrement (see CacheStore interface)
func (*InMemoryStore) Delete ¶
func (c *InMemoryStore) Delete(key string) error
Delete (see CacheStore interface)
func (*InMemoryStore) Flush ¶
func (c *InMemoryStore) Flush() error
Flush (see CacheStore interface)
func (*InMemoryStore) Get ¶
func (c *InMemoryStore) Get(key string, value interface{}) error
Get (see CacheStore interface)
func (*InMemoryStore) Increment ¶
func (c *InMemoryStore) Increment(key string, n int64) (int64, error)
Increment (see CacheStore interface)
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
func NewRedisCache ¶
func NewRedisCache(host string, password string, defaultExpiration time.Duration) *RedisStore
NewRedisCache returns a RedisStore until redigo supports sharding/clustering, only one host will be in hostList
func (*RedisStore) Add ¶
func (c *RedisStore) Add(key string, value interface{}, expires time.Duration) error
Add (see CacheStore interface)
func (*RedisStore) Decrement ¶
func (c *RedisStore) Decrement(key string, delta int64) (newValue int64, err error)
Decrement (see CacheStore interface)
func (*RedisStore) Delete ¶
func (c *RedisStore) Delete(key string) error
Delete (see CacheStore interface)
func (*RedisStore) Get ¶
func (c *RedisStore) Get(key string, ptrValue interface{}) error
Get (see CacheStore interface)
func (*RedisStore) Increment ¶
func (c *RedisStore) Increment(key string, delta int64) (int64, error)
Increment (see CacheStore interface)
Click to show internal directories.
Click to hide internal directories.