Class \Prado\Caching\TEtcdCache
TEtcdCache implements a cache application module based on the distributed, consistent key-value store etcd. etcd is high performance key-value store written in Go which uses the Raft consensus algorithm to manage a highly-available replicated log.
By definition, cache does not ensure the existence of a value even if it never expires. Cache is not meant to be an persistent storage.
To use this module, an etcd instance must be running and reachable on the host specified by setHost and the port specified by setPort which default to 'localhost:2379'. All values are stored within a directory set by setDir which defaults to 'pradocache'.
TEtcdCache only supports etcd API v2 and uses cURL to fire the HTTP GET/PUT/DELETE commands, thus the PHP cURL extension is also needed.
Some usage examples of TEtcdCache are as follows,
$cache = new TEtcdCache(); // TEtcdCache may also be loaded as a Prado application module
$cache->init(null);
$cache->add('value', $value);
$value = $cache->get('value');
If loaded, TEtcdCache will register itself with TApplication as the cache module. It can be accessed via TApplication::getCache().
TEtcdCache may be configured in application configuration file as follows
<module id="cache" class="Prado\Caching\TEtcdCache" Host="localhost" Port="2379" Dir="pradocache" />
Class hierarchy
- \Prado\Caching\TEtcdCache
- \Prado\Caching\TCache implements ICache, ArrayAccess
- \Prado\TModule implements IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 4.0
public
|
flush() : bool
Deletes all values from cache.
Be careful of performing this operation if the cache is shared by multiple applications. |
public
|
|
public
|
|
public
|
|
public
|
init(TXmlElement $config) : mixed
Initializes this module.
This method is required by the IModule interface. |
public
|
|
public
|
|
public
|
|
protected
|
addValue(string $key, string $value, int $expire) : bool
Stores a value identified by a key into cache if the cache does not contain this key.
This is the implementation of the method declared in the parent class. |
protected
|
deleteValue(string $key) : bool
Deletes a value with the specified key from cache
This is the implementation of the method declared in the parent class.
|
protected
|
getValue(string $key) : false|string
Retrieves a value from cache with a specified key.
This is the implementation of the method declared in the parent class. |
protected
|
request(string $method, string $key[, array<string|int, mixed> $value = [] ]) : stdClass
This method does the actual cURL request by generating the method specific
URL, setting the cURL options and adding additional request parameters.
The etcd always returns a JSON string which is decoded and returned to the calling method. |
protected
|
setValue(string $key, string $value, int $expire) : bool
Stores a value identified by a key in cache.
This is the implementation of the method declared in the parent class. |
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |