Documentation ¶
Overview ¶
Package cache defines caching interaction functionalities.
Index ¶
- Constants
- Variables
- type IStore
- type IStoreFactory
- type IStorePool
- type IStoreStrategy
- type InMemoryStore
- func (c *InMemoryStore) Add(key string, value interface{}, expire time.Duration) error
- func (c *InMemoryStore) Decrement(key string, n uint64) (uint64, error)
- func (c *InMemoryStore) Delete(key string) error
- func (c *InMemoryStore) Flush() error
- func (c *InMemoryStore) Get(key string, value interface{}) error
- func (c *InMemoryStore) Increment(key string, n uint64) (uint64, error)
- func (c *InMemoryStore) Replace(key string, value interface{}, expire time.Duration) error
- func (c *InMemoryStore) Set(key string, value interface{}, expire time.Duration) error
- type InMemoryStoreStrategy
- type Provider
- type StoreFactory
Constants ¶
const ( // ID defines the id to be used as the container // registration id of a cache pool instance, as a base id of all other // cache package instances registered in the application container. ID = slate.ID + ".cache" // StoreStrategyTag defines the tag to be assigned to all // container store strategies. StoreStrategyTag = ID + ".store.strategy" // InMemoryStrategyID defines the id to be used as // the container registration id of an in-memory store factory // strategy instance. InMemoryStrategyID = ID + ".store.strategy.in_memory" // MemcachedStrategyID defines the id to be used as // the container registration id of a memcached service store factory // strategy instance. MemcachedStrategyID = ID + ".store.strategy.memcached" // BinaryMemcachedStrategyID defines the id to be used as // the container registration id of a binary connection memcached // service store factory strategy instance. BinaryMemcachedStrategyID = ID + ".store.strategy.binary_memcached" // RedisStrategyID defines the id to be used as // the container registration id of a redis // service store factory strategy instance. RedisStrategyID = ID + ".store.strategy.redis" // StoreFactoryID defines the id to be used as // // the container registration id of a store factory instance. StoreFactoryID = ID + ".store.factory" )
const ( // DEFAULT @todo doc DEFAULT = time.Duration(0) // FOREVER @todo doc FOREVER = time.Duration(-1) )
const ( // EnvID defines the slate.api.cache package base environment variable name. EnvID = slate.EnvID + "_CACHE" )
const ( // InMemoryStoreType defines the value to be used to // declare an in-memory store type. InMemoryStoreType = "in-memory" )
const ( // UnknownStoreType defines the value to be used to // declare an unknown store type. UnknownStoreType = "unknown" )
Variables ¶
var ( // StoresConfigPath contains the configuration path that holds the // cache stores connection configurations. StoresConfigPath = env.String(EnvID+"_STORES_CONFIG_PATH", "slate.api.cache.stores") // ObserveConfig defines the store pool cfg observing flag // used to register in the cfg object an observer of the store // cfg entries list, so it can reset the stores pool. ObserveConfig = env.Bool(EnvID+"_OBSERVE_CONFIG", true) // DefaultExpiration @todo doc. DefaultExpiration = env.Int(EnvID+"_DEFAULT_EXPIRATION", 60000) )
var ( // ErrConfigNotFound defines an error that signal that the // configuration to the requested store was not found. ErrConfigNotFound = fmt.Errorf("cache store config not found") // ErrInvalidStore defines an error that signal that the // given cache configuration was unable to be parsed correctly. ErrInvalidStore = fmt.Errorf("invalid cache store config") // ErrMiss @todo doc ErrMiss = fmt.Errorf("cache key not found") // ErrNotStored @todo doc ErrNotStored = fmt.Errorf("cache element not stored") )
Functions ¶
This section is empty.
Types ¶
type IStore ¶
type IStore 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 uint64) (uint64, error) // Decrement decrements a real number, and returns error if the value // is not real Decrement(key string, data uint64) (uint64, error) // Flush sets all items from the cache. Flush() error }
IStore is the interface of a cache backend layer.
type IStoreFactory ¶
type IStoreFactory interface { Register(strategy IStoreStrategy) error Create(cfg config.IConfig) (IStore, error) }
IStoreFactory defined the interface of a store factory instance.
type IStorePool ¶
IStorePool defines the interface of a store pool instance.
func NewStorePool ¶
func NewStorePool( cfg config.IManager, factory IStoreFactory, ) (IStorePool, error)
NewStorePool will instantiate a new relational database store pool instance.
type IStoreStrategy ¶
type IStoreStrategy interface { Accept(cfg config.IConfig) bool Create(cfg config.IConfig) (IStore, error) }
IStoreStrategy @todo doc
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
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{}, expire time.Duration, ) error
Add (see IStore interface)
func (*InMemoryStore) Decrement ¶
func (c *InMemoryStore) Decrement( key string, n uint64, ) (uint64, error)
Decrement (see IStore interface)
func (*InMemoryStore) Delete ¶
func (c *InMemoryStore) Delete( key string, ) error
Delete (see IStore interface)
func (*InMemoryStore) Get ¶
func (c *InMemoryStore) Get( key string, value interface{}, ) error
Get (see IStore interface)
func (*InMemoryStore) Increment ¶
func (c *InMemoryStore) Increment( key string, n uint64, ) (uint64, error)
Increment (see IStore interface)
type InMemoryStoreStrategy ¶
type InMemoryStoreStrategy struct{}
InMemoryStoreStrategy @todo doc
func NewInMemoryStoreStrategy ¶
func NewInMemoryStoreStrategy() *InMemoryStoreStrategy
NewInMemoryStoreStrategy @todo doc
type Provider ¶
type Provider struct{}
Provider defines the slate.cache module service provider to be used on the application initialization to register the caching services.
type StoreFactory ¶
type StoreFactory []IStoreStrategy
StoreFactory is a persistence store generator based on a registered list of store generation strategies.
func (StoreFactory) Create ¶
func (f StoreFactory) Create( cfg config.IConfig, ) (IStore, error)
Create will instantiate and return a new store loaded by a configuration instance.
func (*StoreFactory) Register ¶
func (f *StoreFactory) Register( strategy IStoreStrategy, ) error
Register will register a new store factory strategy to be used on creation requests.