Download .zip |
Info | View files (7) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2020-03-28 (20 hours ago) | Not yet rated by the users | Total: 87 This week: 2 | All time: 9,441 This week: 205 |
Version | License | PHP version | Categories | |||
cacheone 1.0.1 | GNU Lesser Genera... | 5 | Networking, PHP 5, Cache |
CacheOne is a cache class of service for php. It supports Redis, Memcache and/or APCU.
Unlikely other cache libraries, this library is based in group (optional). So it's suitable to invalidate a single key or an entire group of elements.
use eftec\CacheOne;
include "vendor/autoload.php"; // composer's autoload
$cache=new CacheOne("redis","127.0.0.1","",6379);
$cacheValue=$cache->get('','countries'); // read the cache (if any) otherwise false
if($cacheValue===false) {
echo "generating a new list of countries..<br>";
$countries=['USA','Canada','Japan','Chile'];
$cache->set('','countries',$countries,500); // store into the cache for 500 seconds.
} else {
echo "read from cache<br>";
$countries=$cacheValue;
}
var_dump($countries);
Creates a new connection using redis
use eftec\CacheOne;
include "../vendor/autoload.php";
$cache=new CacheOne("redis","127.0.0.1","",6379);
Creates a new connection using apcu
use eftec\CacheOne;
include "../vendor/autoload.php";
$cache=new CacheOne("apcu");
Creates a new connection using memcache
use eftec\CacheOne;
include "../vendor/autoload.php";
$cache=new CacheOne("memcache","127.0.0.1");
or creating a new connection, or redis, or memcache or apcu (it takes the first available)
use eftec\CacheOne;
include "../vendor/autoload.php";
$cache=new CacheOne("auto");
> function set($group, $key, $value, $duration = 1440): bool
It store a value inside a group and a key. It returns false if the operation failed.
$cache->set("group","key1","hello world",500);
$cache->set("group","key2","hola mundo",500);
Group is optional and it could be used if we need to invalidate (delete) an entire group.
> function get($group, $key, $defaultValue = false)
It gets a value stored in a group (optional) and key. If the value is not found then it returns false. Note: a false value could be a valid value.
$result=$cache->get("group","key1");
$result=$cache->get("","key2");
$result=$cache->get("","key2","not found"); // if not key2 (groupless) then it returns not found
> function invalidate($group = '', $key = ''): bool
It invalidates a specific key. If the operation fails, then it returns false
$cache->invalidate("group",key1"); // invalidate a key inside a group
$cache->invalidate("",key1"); // invalidate a key without a group.
> invalidateGroup($group): bool
It invalidates every key(s) inside a group of groups. It also clean the catalog of the group and sets it to an empty array.
$cache->invalidateGroup("group"); // invalidate all keys inside group
$cache->invalidateGroup(["group1","group2"]); // invalidate all key inside group1 and group2
> invalidateAll()
It invalidates (and delete all the redis repository, memcache or apcu)
$cache->invalidateAll();
It sets how the values are serialized. By default it's PHP.
$cache->setSerializer('php'); // set the serializer to php (default value)
$cache->setSerializer('json-array'); // set the serializer to json-array
$cache->setSerializer('json-object'); // set the serializer to json-object
$cache->setSerializer('none'); // set the serializer to none (the value must be serialized)
Get the how the values are serialized.
$type=$cache->getSerializer(); // get php,json-array,json-object or none
> select($dbindex)
It selects a different database. By default the database is 0.
$cache->select(1);
MIT License. Copyright Jorge Castro Castillo
Files |
File | Role | Description | ||
---|---|---|---|---|
lib (1 file) | ||||
test (2 files) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files | / | test |
File | Role | Description |
---|---|---|
bootstrap.php | Aux. | Auxiliary script |
CacheOneTest.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.