amber / cache
Simple Cache.
Installs: 1 319
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=7.2.0
- amber/common: dev-master
- psr/cache: ^1.0
- psr/simple-cache: ^1.0
Requires (Dev)
- lavoiesl/php-benchmark: ^1.4
- phpfastcache/phpfastcache: ^7.0
- phpunit/phpunit: ^8.0
- squizlabs/php_codesniffer: ^3.3
- symfony/cache: ^4.2
- symfony/var-dumper: ^4.2
This package is auto-updated.
Last update: 2019-11-22 13:50:33 UTC
README
Amber/Cache
Simple and fast cache system implementing PSR-16: interface for caching libraries
Getting started
Installation
With Composer
$ composer require amber/cache
API Usage
use Amber\Cache\Cache; $cache = Cache::getInstance();
Drivers
Alternatively you can set the driver before geting the instance of the cache.
use Amber\Cache\Cache; $cache = Cache::driver('file');
You can choose from these drivers:
$drivers = [ 'file' => 'Amber\Cache\Driver\SimpleCache', 'json' => 'Amber\Cache\Driver\JsonCache', 'array' => 'Amber\Cache\Driver\ArrayCache', 'apcu' => 'Amber\Cache\Driver\ApcuCache', ];
Or you could set the driver class:
$cache = Cache::driver(Amber\Cache\Driver\SimpleCache::class);
Finally you could instantiate the driver by yourself:
$cache = new \Amber\Cache\Driver\SimpleCache();
get()
Fetches a value from the cache.
$cache->get($key, $default = null);
set()
Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
$cache->set($key, $value, $ttl = null);
delete()
Delete an item from the cache by its unique key.
$cache->delete($key);
clear()
Wipes clean the entire cache's keys.
$cache->clear();
has()
Determines whether an item is present in the cache.
$cache->has($key);
Multiple actions
getMultiple()
Obtains multiple cache items by their unique keys.
$cache->getMultiple($keys, $default = null);
setMultiple()
Persists a set of key => value pairs in the cache, with an optional TTL.
$cache->setMultiple($values, $ttl = null);
deleteMultiple()
Deletes multiple cache items in a single operation.
$cache->deleteMultiple($keys);
Static Usage
You can use all the method from the Cache class statically, like this:
use Amber\Cache\Cache; Cache::set('key', 'value'); Cache::has('key'); // Returns true Cache::get('key'); // Returns "value" Cache::delete('key'); // Set the driver and then call the desired method. Cache::driver('json')->set('key', 'value');