Documentation ¶
Overview ¶
A minimalistic cache implementation for golang using, hopefully clusterized, redis servers.
Index ¶
- Variables
- type Cache
- func (c *Cache) CheckAndSet(key interface{}, val interface{}, oserial int64) (int64, error)
- func (c *Cache) Del(key interface{}) error
- func (c *Cache) Get(key interface{}, val interface{}) (int64, error)
- func (c *Cache) Hits() int64
- func (c *Cache) Loads() int64
- func (c *Cache) Misses() int64
- func (c *Cache) Set(key interface{}, val interface{}) (int64, error)
- type CacheOptions
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Main object for the cache
func NewCache ¶
func NewCache(connector Connector, options *CacheOptions) (*Cache, error)
NewCache returns a Cache with given connector and options. If no options given, i.e. nil, it set them with default values.
func (*Cache) CheckAndSet ¶
CheckAndSet put a value with a key into the Cache, ONLY IF it has no newer values with, i.e. no update since, a given serial. It takes key, value parameters as an interface{} type and performs marshal for them. If succeed, it returns a serial number(an unix timestamp in millis) for the value. If a value of newer serial already exists, CheckAndSet would fail with ErrSetFailed.
func (*Cache) Del ¶
Del remove a cached value for the given key. It takes a key parameter as an interface{} type and performs marshal for it.
func (*Cache) Get ¶
Get returns a cached value using bound Connector. It takes key, value parameters as an interface{} type and performs marshal/unmarshal for them.
func (*Cache) Set ¶
Set put a value with a key into the Cache. It takes key, value parameters as an interface{} type and performs marshal for them. If succeed, it returns a serial number(an unix timestamp in millis) for the value. If a value of newer serial already exists, Set would fail with ErrSetFailed.
type CacheOptions ¶
type CacheOptions struct { // Marshaling function to serialize a key or a value for the cache Marshal func(interface{}) ([]byte, error) // Unmarshaling function to deserialize a key or a value for the cache Unmarshal func([]byte, interface{}) error // Cache expiration time Expiration time.Duration }
CacheOptions describes various paramters to control cache behaviors