Superbalist / laravel4-psr6-cache-bridge by superbalist

A PSR6 cache implementation for Laravel 4
8,277
1
33
Package Data
Maintainer Username: superbalist
Maintainer Contact: info@superbalist.com (Superbalist.com a division of Takealot Online (Pty) Ltd)
Package Create Date: 2017-07-03
Package Last Update: 2017-07-04
Language: PHP
License: MIT
Last Refreshed: 2020-10-23 15:19:23
Package Statistics
Total Downloads: 8,277
Monthly Downloads: 97
Daily Downloads: 5
Total Stars: 1
Total Watchers: 33
Total Forks: 0
Total Open Issues: 0

laravel4-psr6-cache-bridge

A PSR6 cache implementation for Laravel 4.

Author Build Status StyleCI Software License Packagist Version Total Downloads

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();