superbalist / laravel4-psr6-cache-bridge
A PSR6 cache implementation for Laravel 4
Installs: 18 979
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 33
Forks: 1
Open Issues: 0
Requires
- php: >=5.6.0
- illuminate/cache: ^4.0
- illuminate/support: ^4.0
- psr/cache: ^1.0
Requires (Dev)
- mockery/mockery: ^0.9.5
- phpunit/phpunit: ^5.5
This package is auto-updated.
Last update: 2024-08-11 23:46:50 UTC
README
A PSR6 cache implementation for Laravel 4.
This library is based off the Laravel 5 implementation by madewithlove/illuminate-psr-cache-bridge.
Installation
composer require superbalist/laravel4-psr6-cache-bridge
Register the service provider in app.php
'providers' => [ // ... 'Superbalist\Laravel4PSR6CacheBridge\ServiceProvider' ]
Usage
You can now start using or injecting the CacheItemPoolInterface
implementation for libraries which expect
a PSR6 cache implementation.
use DateTimeImmutable; use Psr\Cache\CacheItemPoolInterface; use Superbalist\Laravel4PSR6CacheBridge\LaravelCacheItem::class; use Superbalist\Laravel4PSR6CacheBridge\LaravelCacheItemPool::class; $pool = app(CacheItemPoolInterface::class); // or $pool = app(LaravelCacheItemPool::class); // save an item with an absolute ttl $item = new LaravelCacheItem('first_name', 'Bob', true); $item->expiresAt(new DateTimeImmutable('2017-06-30 14:30:00')); $pool->save($item); // save an item with a relative ttl $item = new LaravelCacheItem('first_name', 'Bob', true); $item->expiresAfter(60); $pool->save($item); // save an item permanently $item = new LaravelCacheItem('first_name', 'Bob', true); $pool->save($item); // retrieve an item $item = $pool->get('first_name'); // working with an item var_dump($item->getKey()); var_dump($item->get()); var_dump($item->isHit()); // retrieve one or many items $items = $pool->getItems(['first_name']); var_dump($items['first_name']); // check if an item exists in cache var_dump($pool->hasItem('first_name')); // wipe out all items $pool->clear(); // delete an item $pool->deleteItem('first_name'); // delete one or many items $pool->deleteItems(['first_name']); // save a deferred item $item = new LaravelCacheItem('first_name', 'Bob', true); $item->expiresAt(new DateTimeImmutable('+1 hour')); $pool->saveDeferred($item); // commit all deferred items $pool->commit();