dspacelabs/cache

This package is abandoned and no longer maintained. The author suggests using the sonsofphp/cache package instead.

Generic Caching Library for PHP

dev-master / 0.1.x-dev 2016-01-17 01:13 UTC

This package is not auto-updated.

Last update: 2023-11-22 13:39:35 UTC


README

Packagist Packagist Pre Release Packagist Packagist

Generic Caching Library for PHP

Installation

composer require dspacelabs/cache

Current Stable Release: Packagist

Current Pre Release: Packagist Pre Release

Usage

<?php

use Dspacelabs\Component\Cache\Adapter\ArrayAdapter;
use Dspacelabs\Component\Cache\CacheItemPool;

$pool = new CacheItemPool(new ArrayAdapter());

# General Usage
$item = $pool->getItem('sql.results');
if (!$item->isHit()) {
    $value = longRunningQuery();
    $item->set($value);
    $pool->save($item);
}
$results = $item->get();

# Delete items from cache
$sqlResults = $pool->getItem('sql.results');
$sqlResults->exists(); // returns true

$sqlResultsTwo = $pool->getItem('sql.results.two');
$sqlResultsTwo->exists(); // returns true

$pool->deleteItems(array('sql.results'));

$sqlResults->exists(); // returns false
$sqlResultsTwo->exists(); // returns true

# Clear entire cache
$sqlResults = $pool->getItem('sql.results');
$sqlResults->exists(); // returns true

$sqlResultsTwo = $pool->getItem('sql.results.two');
$sqlResultsTwo->exists(); // returns true

$pool->clear();

$sqlResults->exists(); // returns false
$sqlResultsTwo->exists(); // returns false

# Cached value expires after 3600 seconds
$item = $pool->getItem('sql.results');
$item->expiresAfter(3600);
$pool->save($item);

Change Log

See CHANGELOG.md.

License

MIT

See LICENSE.