InitPHP\Cache\Handler\Memcache stores items in Memcached. It works with either
the modern Memcached
extension (preferred) or the legacy Memcache extension; if both are present,
Memcached is used.
| Option | Type | Default | Description |
|---|---|---|---|
prefix |
string |
cache_ |
Prepended to keys. |
host |
string |
127.0.0.1 |
Server host. |
port |
int |
11211 |
Server port. |
weight |
int |
1 |
Server weight (Memcached only). |
default_ttl |
int |
0 |
Expiry used when set() is called with no TTL. 0 means "no expiry". |
use InitPHP\Cache\Cache;
use InitPHP\Cache\Handler\Memcache;
$cache = Cache::create(Memcache::class, [
'host' => '127.0.0.1',
'port' => 11211,
]);
$cache->set('fragment:nav', $html, 600);
$cache->get('fragment:nav');- Each value is stored as a small serialised envelope, so
null,false, arrays and objects round-trip exactly. - TTLs are delegated to the server. When
set()is called without a TTL, thedefault_ttloption is used (0= no expiry). clear()callsflush(), which clears the entire Memcached instance — it is not limited byprefix.
If neither extension is available, or the server cannot be reached, the handler
throws a CacheException.