Documentation
¶
Index ¶
- type MemcachedCache
- func (c *MemcachedCache) Close(correlationId string) error
- func (c *MemcachedCache) Configure(config *cconf.ConfigParams)
- func (c *MemcachedCache) IsOpen() bool
- func (c *MemcachedCache) Open(correlationId string) error
- func (c *MemcachedCache) Remove(correlationId string, key string) error
- func (c *MemcachedCache) Retrieve(correlationId string, key string) (value interface{}, err error)
- func (c *MemcachedCache) RetrieveAs(correlationId string, key string, result interface{}) (value interface{}, err error)
- func (c *MemcachedCache) SetReferences(references cref.IReferences)
- func (c *MemcachedCache) Store(correlationId string, key string, value interface{}, timeout int64) (result interface{}, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemcachedCache ¶
type MemcachedCache struct {
// contains filtered or unexported fields
}
MemcachedCache are distributed cache that stores values in Memcaches caching service.
The current implementation does not support authentication.
Configuration parameters:
- connection(s):
- discovery_key: (optional) a key to retrieve the connection from IDiscovery
- host: host name or IP address
- port: port number
- uri: resource URI or connection string with all parameters in it
- options:
- max_size: maximum number of values stored in this cache (default: 1000)
- max_key_size: maximum key length (default: 250)
- max_expiration: maximum expiration duration in milliseconds (default: 2592000)
- max_value: maximum value length (default: 1048576)
- pool_size: pool size (default: 5)
- reconnect: reconnection timeout in milliseconds (default: 10 sec)
- retries: number of retries (default: 3)
- timeout: default caching timeout in milliseconds (default: 1 minute)
- failures: number of failures before stop retrying (default: 5)
- retry: retry timeout in milliseconds (default: 30 sec)
- idle: idle timeout before disconnect in milliseconds (default: 5 sec)
References:
- *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection
Example:
cache := NewMemcachedCache(); cache.Configure(cconf.NewConfigParamsFromTuples( "host", "localhost", "port", 11211, )); err := cache.Open("123") ... ret, err := cache.Store("123", "key1", []byte("ABC")) if err != nil { ... } res, err := cache.Retrive("123", "key1") value, _ := res.([]byte) fmt.Println(string(value)) // Result: "ABC"
func NewMemcachedCache ¶
func NewMemcachedCache() *MemcachedCache
NewMemcachedCache method are creates a new instance of this cache.
func (*MemcachedCache) Close ¶
func (c *MemcachedCache) Close(correlationId string) error
Close method are closes component and frees used resources. Parameters: - correlationId (optional) transaction id to trace execution through call chain. - callback callback function that receives error or nil no errors occured.
func (*MemcachedCache) Configure ¶
func (c *MemcachedCache) Configure(config *cconf.ConfigParams)
Configures component by passing configuration parameters. - config configuration parameters to be set.
func (*MemcachedCache) IsOpen ¶
func (c *MemcachedCache) IsOpen() bool
IsOpen Checks if the component is opened. Returns true if the component has been opened and false otherwise.
func (*MemcachedCache) Open ¶
func (c *MemcachedCache) Open(correlationId string) error
Open method are opens the component. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
Retruns: error or nil no errors occured.
func (*MemcachedCache) Remove ¶
func (c *MemcachedCache) Remove(correlationId string, key string) error
Remove method are removes a value from the cache by its key. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
- key a unique value key.
Retruns: an error or nil for success
func (*MemcachedCache) Retrieve ¶
func (c *MemcachedCache) Retrieve(correlationId string, key string) (value interface{}, err error)
Retrieve method are retrieves cached value from the cache using its key. If value is missing in the cache or expired it returns nil. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
- key a unique value key.
Retruns value *memcache.Item, err error cached value or error.
func (*MemcachedCache) RetrieveAs ¶
func (c *MemcachedCache) RetrieveAs(correlationId string, key string, result interface{}) (value interface{}, err error)
Retrieve method are retrieves cached value from the cache using its key. If value is missing in the cache or expired it returns nil. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
- key a unique value key.
Retruns value *memcache.Item, err error cached value or error.
func (*MemcachedCache) SetReferences ¶
func (c *MemcachedCache) SetReferences(references cref.IReferences)
SetReferences are sets references to dependent components.
- references references to locate the component dependencies.
func (*MemcachedCache) Store ¶
func (c *MemcachedCache) Store(correlationId string, key string, value interface{}, timeout int64) (result interface{}, err error)
Store method are stores value in the cache with expiration time. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
- key a unique value key.
- value a value to store.
- timeout expiration timeout in milliseconds.
Returns: error or nil for success