https://github.com/kodedphp/cache-extended
A PSR-6 caching library.
https://github.com/kodedphp/cache-extended
cache caching filecache json memcached psr-6 redis
Last synced: 6 months ago
JSON representation
A PSR-6 caching library.
- Host: GitHub
- URL: https://github.com/kodedphp/cache-extended
- Owner: kodedphp
- License: bsd-3-clause
- Created: 2018-10-21T07:44:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-03T13:47:05.000Z (over 4 years ago)
- Last Synced: 2025-06-23T20:10:05.950Z (7 months ago)
- Topics: cache, caching, filecache, json, memcached, psr-6, redis
- Language: PHP
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Koded - Extended Caching Library
================================
[](https://packagist.org/packages/koded/cache-extended)
[](https://travis-ci.org/kodedphp/cache-extended)
[](https://scrutinizer-ci.com/g/kodedphp/cache-extended/?branch=master)
[](https://scrutinizer-ci.com/g/kodedphp/cache-extended/?branch=master)
[](https://php.net/)
[](LICENSE)
A [PSR-6][psr-6] caching library for PHP 7 using several caching technologies.
Requirements
------------
- Linux machine
- PHP 8
Recommended cache technologies are
- Redis server
- Memcached
Recommended PHP modules
- [Redis extension]
- [Memcached extension]
For developing purposes you can use
- Memory client (default)
- File client
Usage
-----
- create an instance of `CacheItemPoolInterface` with desired caching technology
- manipulate the cache items with the pool instance
```php
$cache = CachePool::use('redis');
$item = $cache->getItem('fubar');
$item->set('some value');
$item->expiresAfter(new DateTime('3 days'));
$cache->save();
```
**The pool instance is created only once.**
> `CachePool::use()` accepts specific parameters for the underlying caching technology.
This method uses the [Koded Simple Cache][koded-cache-simple] package.
Please see the README in that repository for the specific arguments.
You can grab the cache client if you want to use it directly
```php
/** $var Koded\Caching\Cache $client */
$client = $cache->client();
```
Deferring the items
-------------------
To postpone the saving of the cache items (store all items "at once"),
you can use the `saveDeferred()` method. These cache items are saved when you
- execute `commit()`
- when `CacheItemPoolInterface` instance is destroyed
**Keep in mind that `commit()` is not an atomic operation.**
There is no guarantee that all items will be saved, because anything can
happen while `save()` runs (network, client crash, etc).
```php
$cache->saveDeferred($event);
$cache->saveDeferred($counter);
// ... do some stuff
// store this now
$cache->save($dependency);
// ... do more stuff
$cache->saveDeferred($updates);
$cache->saveDeferred($extras);
// Store all deferred items
$cache->commit();
```
License
-------
The code is distributed under the terms of [The 3-Clause BSD license](LICENSE).
[psr-6]: http://www.php-fig.org/psr/psr-6/
[koded-cache-simple]: https://github.com/kodedphp/cache-simple#configuration-directives
[Redis extension]: https://github.com/phpredis/phpredis/blob/develop/INSTALL.markdown
[Memcached extension]: https://github.com/php-memcached-dev/php-memcached