Generic caching library for php
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
src
tests
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

Dspacelabs/Component/Cache Travis

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.