PHP code example of district5 / cache-lib
1. Go to this page and download the library: Download district5/cache-lib library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
district5 / cache-lib example snippets
$key = 'name';
$value = 'Joe Bloggs';
$adapter = new \District5\CacheLib\Adapters\AdapterApc(
[
'prefix' => '' // default
]
);
$adapter->get($key, $default = null); // returns false or mixed
$adapter->set($key, $value, $ttl = 86400); // returns bool
$adapter->has($key); // returns bool
$adapter->renew($key, $ttl); // returns bool
$adapter->remove($key); // returns bool
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns bool
$adapter->flush(); // returns bool
$key = 'name';
$value = 'Joe Bloggs';
$adapter = new \District5\CacheLib\Adapters\AdapterFileSystem(
[
'prefix' => '', // optional
'path' => '/some/writable/directory'
]
);
$adapter->get($key, $default = null); // returns false or mixed
$adapter->set($key, $value, $ttl = 86400); // returns bool
$adapter->has($key); // returns bool
$adapter->renew($key, $ttl); // returns bool
$adapter->remove($key); // returns bool
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns bool
$adapter->flush(); // returns bool
$key = 'name';
$value = 'Joe Bloggs';
$adapter = new \District5\CacheLib\Adapters\AdapterMemcache(
[
'prefix' => '', // optional
'servers' => [
[
'host' => 'a-host-name',
'port' => 11211,
'timeout' => 60,
'weight' => 1
],
[
'host' => 'another-host-name',
'port' => 11211,
'timeout' => 60,
'weight' => 1
]
]
]
);
$adapter->get($key, $default = null); // returns false or mixed
$adapter->set($key, $value, $ttl = 86400); // returns bool
$adapter->has($key); // returns bool
$adapter->renew($key, $ttl); // returns bool
$adapter->remove($key); // returns bool
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns bool
$adapter->flush(); // returns bool
$key = 'name';
$value = 'Joe Bloggs';
$adapter = new \District5\CacheLib\Adapters\AdapterMemcached(
[
'prefix' => '', // optional
'persistent_id' => '', // optional
'servers' => [
[
'host' => 'a-host-name',
'port' => 11211,
'weight' => 1
],
[
'host' => 'another-host-name',
'port' => 11211,
'weight' => 1
]
]
]
);
$adapter->get($key, $default = null); // returns false or mixed
$adapter->set($key, $value, $ttl = 86400); // returns bool
$adapter->has($key); // returns bool
$adapter->renew($key, $ttl); // returns bool
$adapter->remove($key); // returns bool
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns bool
$adapter->flush(); // returns bool
$key = 'name';
$value = 'Joe Bloggs';
$adapter = new \District5\CacheLib\Adapters\AdapterNull([]);
$adapter->get($key, $default = null); // returns false
$adapter->set($key, $value, $ttl = 86400); // returns false
$adapter->has($key); // returns false
$adapter->renew($key, $ttl); // returns false
$adapter->remove($key); // returns false
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns false
$adapter->flush(); // returns false