Documentation ¶
Index ¶
- Variables
- func Add(ctx context.Context, key string, value interface{}, expire time.Duration) error
- func Dec(ctx context.Context, key string, value uint64) (int64, error)
- func Delete(ctx context.Context, key string) error
- func Inc(ctx context.Context, key string, value uint64) (int64, error)
- func Replace(ctx context.Context, key string, value interface{}, expire time.Duration) error
- func Set(ctx context.Context, key string, value interface{}, expire time.Duration) error
- func WithCache(ctx context.Context, cache Cache) context.Context
- type Cache
- type Item
- type MemcacheOptionsFunc
- type RedisOptionsFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrCacheMiss means that a Get failed because the item wasn't present. ErrCacheMiss = errors.New("cache: miss") // ErrNotStored means the conditional write (Add or Replace) failed because // the condition was not met. ErrNotStored = errors.New("cache: not stored") // Null is the null Cache instance. Null = &nullCache{} )
Functions ¶
Types ¶
type Cache ¶
type Cache interface { // Get gets the item for the given key. Get(key string) *Item // GetMulti gets the items for the given keys. GetMulti(keys ...string) ([]*Item, error) // Set sets the item in the cache. Set(key string, value interface{}, expire time.Duration) error // Add sets the item in the cache, but only if the key does not already exist. Add(key string, value interface{}, expire time.Duration) error // Replace sets the item in the cache, but only if the key already exists. Replace(key string, value interface{}, expire time.Duration) error // Delete deletes the item with the given key. Delete(key string) error // Inc increments a key by the value. Inc(key string, value uint64) (int64, error) // Dec decrements a key by the value. Dec(key string, value uint64) (int64, error) }
Cache represents a cache instance.
func FromContext ¶
FromContext returns the instance of Cache in the context.
func NewMemcache ¶
func NewMemcache(uri string, opts ...MemcacheOptionsFunc) Cache
NewMemcache create a new Memcache cache instance.
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item represents an item to be returned or stored in the cache
type MemcacheOptionsFunc ¶
MemcacheOptionsFunc represents an configuration function for Memcache.
func WithIdleConns ¶
func WithIdleConns(size int) MemcacheOptionsFunc
WithIdleConns configures the Memcache max idle connections.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) MemcacheOptionsFunc
WithTimeout configures the Memcache read and write timeout.
type RedisOptionsFunc ¶
RedisOptionsFunc represents an configuration function for Redis.
func WithPoolSize ¶
func WithPoolSize(size int) RedisOptionsFunc
WithPoolSize configures the Redis pool size.
func WithPoolTimeout ¶
func WithPoolTimeout(timeout time.Duration) RedisOptionsFunc
WithPoolTimeout configures the Redis pool timeout.
func WithReadTimeout ¶
func WithReadTimeout(timeout time.Duration) RedisOptionsFunc
WithReadTimeout configures the Redis read timeout.
func WithWriteTimeout ¶
func WithWriteTimeout(timeout time.Duration) RedisOptionsFunc
WithWriteTimeout configures the Redis write timeout.
Click to show internal directories.
Click to hide internal directories.