Easy to use, auto configurable, extensible cache provider
composer require maslosoft/cache
This cache library provides consistent interface for popular cache systems. It uses best cache provider available based on configurable list.
Also provides logic-less getting of cache value, with fallback to callable.
If you need some modern cache with just basic features here it is.
It implements only basic cache operations:
- has - to check if has key in cache
- get - to get cached value by key
- set - to set value to cache
- remove - to remove cached value
- clear - to clear entira cache
- PHP 5.6+
- composer
Use composer to install extension:
composer require maslosoft/cache:"*"
Setup cache. After calling init
any further instance will be configured same as below $cache
.
use Maslosoft\Cache\Cache;
$cache = new Cache();
// Setup something here...
$cache->timeout = 1244;
$cache->init();
<?php
use Maslosoft\Cache\Cache;
$cache = new Cache();
// Init configuration, now it is available anywhere
// By default it will try some cache providers and select best available.
$cache->init();
$key = 1;
if(!$cache->has($key))
{
$cache->set($key, 'Some value');
}
echo $cache->get($key);
And that's it!