dspacelabs / cache
Generic Caching Library for PHP
Installs: 1 384
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Requires (Dev)
- mockery/mockery: ~1.0@dev
- phpunit/phpunit: ~4.7
This package is not auto-updated.
Last update: 2023-11-22 13:39:35 UTC
README
Generic Caching Library for PHP
Installation
composer require dspacelabs/cache
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.