Documentation
¶
Index ¶
- Constants
- type Cache
- func (c *Cache) Clear(ctx context.Context) error
- func (c *Cache) Delete(ctx context.Context, key interface{}) error
- func (c *Cache) Get(ctx context.Context, key, v interface{}) error
- func (c *Cache) Invalidate(ctx context.Context, options InvalidateOptions) error
- func (c *Cache) Set(ctx context.Context, key interface{}, value interface{}, options Options) error
- type InvalidateOptions
- type Options
- type Provider
- type Store
Constants ¶
const ( // MemoryDriver is the Redis Driver, depicted // in the environment. MemoryDriver = "memory" // RedisDriver is the Redis Driver, depicted // in the environment. RedisDriver = "redis" // MemcacheDriver is the Memcached Driver, depicted // in the environment. MemcacheDriver = "memcache" // RememberForever is an alias for setting the // cache item to never be removed. RememberForever = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// Driver is the current store being used, it can be
// MemoryDriver, RedisDriver or MemcachedDriver.
Driver string
// contains filtered or unexported fields
}
Cache defines the methods for interacting with the cache layer.
func Load ¶
Load initialises the cache store by the environment. It will load a Driver into memory ready for setting getting setting and deleting. Drivers supported are Memory Redis and MemCached. Returns ErrInvalidDriver if the Driver passed does not exist.
func (*Cache) Get ¶
Get retrieves a specific item from the cache by key. Values are automatically marshalled for use with Redis & Memcache.
func (*Cache) Invalidate ¶
func (c *Cache) Invalidate(ctx context.Context, options InvalidateOptions) error
Invalidate removes items from the cache via the InvalidateOptions passed.
type InvalidateOptions ¶
type InvalidateOptions struct {
// Tags allows to specify associated tags to the
// current value.
Tags []string
}
InvalidateOptions represents the options for invalidating the cache.
type Options ¶
type Options struct {
// Expiration allows to specify a global expiration
// time hen setting a value.
Expiration time.Duration
// Tags allows specifying associated tags to the
// current value.
Tags []string
}
Options represents the cache store available options when using Set().
type Provider ¶
type Provider interface {
// Ping the store.
Ping() error
// Validate checks the environment for errors.
Validate() error
// Driver returns the store's name.
Driver() string
// Store returns the interface for use within
// the cache.
Store() store.StoreInterface
}
Provider defines the methods for a cache Provider.
func NewMemcache ¶
NewMemcache creates a new memcached store and returns a provider.
type Store ¶
type Store interface {
// Get retrieves a specific item from the cache by key. Values are
// automatically marshalled for use with Redis & Memcache.
Get(ctx context.Context, key, v interface{}) error
// Set stores a singular item in memory by key, value
// and options (tags and expiration time). Values are automatically
// marshalled for use with Redis & Memcache.
Set(ctx context.Context, key interface{}, value interface{}, options Options) error
// Delete removes a singular item from the cache by
// a specific key.
Delete(ctx context.Context, key interface{}) error
// Invalidate removes items from the cache via the
// InvalidateOptions passed.
Invalidate(ctx context.Context, options InvalidateOptions) error
// Clear removes all items from the cache.
Clear(ctx context.Context) error
}
Store defines methods for interacting with the caching system.
