Documentation ¶
Index ¶
- Variables
- func NewGobEncoding() *gobEncoding
- func NewJsonEncoding() *jsonEncoding
- func NewLiteralEncoding(fallback Encoding) *literalEncoding
- func NewMemcacheClient(c *memcache.Client, encoding Encoding) *memcacheClient
- func NewRedisClient(c *redis.Client, encoding Encoding) *redisClient
- func TtlForExpiration(t time.Time) time.Duration
- type Client
- type Decoder
- type Encoder
- type Encoding
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCacheMiss = errors.New("cache miss") ErrNotStored = errors.New("not stored") ErrNotAPointer = errors.New("argument to Get() must be a pointer") ErrNotANumber = errors.New("value currently stored is not a number") )
View Source
var DefaultEncoding = GobEncoding
View Source
var NeverExpire time.Time
Functions ¶
func NewGobEncoding ¶
func NewGobEncoding() *gobEncoding
func NewJsonEncoding ¶
func NewJsonEncoding() *jsonEncoding
func NewLiteralEncoding ¶
func NewLiteralEncoding(fallback Encoding) *literalEncoding
NewLiteralEncoding is an encoding that will try its best to store the data as is, but fallback on another encoder if not possible.
func NewMemcacheClient ¶
Example ¶
memcacheClient := memcache.New("localhost:11211") NewMemcacheClient(memcacheClient, DefaultEncoding)
Output:
func NewRedisClient ¶
func NewRedisClient(c *redis.Client, encoding Encoding) *redisClient
Example ¶
opts, err := redis.ParseURL("") if err != nil { panic(err) } client := redis.NewClient(opts) NewRedisClient(client, DefaultEncoding)
Output:
Types ¶
type Client ¶
type Client interface { // Get gets the item for the given key. // Returns nil for a cache miss. // The key must be at most 250 bytes in length. Get(key string, data interface{}) error // Set writes the given item, unconditionally. Set(key string, data interface{}, expiration time.Time) error // Add writes the given item, if no value already exists for its // key. ErrNotStored is returned if that condition is not met. Add(key string, data interface{}, expiration time.Time) error // Delete deletes the item with the provided key, if it exists. Delete(key string) error // Increment adds delta to the currently stored number // If the key does not exist, it will be initialized to 0 with no expiration. // If the value overflows, it will loop around from 0 // For many client implementations, you need to be using a LiteralEncoding for this feature to work Increment(key string, delta uint64) (uint64, error) // Decrement subtracts delta to the currently stored number // If the key does not exist, it will be initialized to 0 with no expiration, which will make it overflow. // If the value overflows, it will loop around from MaxUint64 // For many client implementations, you need to be using a LiteralEncoding for this feature to work Decrement(key string, delta uint64) (uint64, error) }
Client is inspired from *memcached.Client
func NewMemoryClient ¶
func NewMemoryClient() Client
NewMemoryClient returns a Client that only stores in memory. Useful for stubbing tests.
type Encoding ¶
var GobEncoding Encoding = NewGobEncoding()
var JsonEncoding Encoding = NewJsonEncoding()
Click to show internal directories.
Click to hide internal directories.