genkgo / cache
Installs: 19 215
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: >=5.6
Requires (Dev)
- phpunit/phpunit: ~4.0
- phpunit/phpunit-mock-objects: ~2.0
- predis/predis: ~1.0.3
- tedivm/stash: ~0.12.3
Suggests
- predis/predis: ~1.0.3
- tedivm/stash: ~0.12.3
README
PHP Cache library using mechanisms as originally proposed by Anthony Ferrara.
Credit to Anthony Ferrara.
All the credit for the cache mechanisms go to @ircmaxell. Please go and read his blog post explaining why cache should be implemented this way.
Installation
Requires PHP 5.5 or later. There are no plans to support PHP 5.4 or PHP 5.3. In case this is an obstacle for you, conversion should be no problem. The library is very small.
It is installable and autoloadable via Composer as genkgo/cache.
Quality
To run the unit tests at the command line, issue phpunit -c tests/
. PHPUnit is required.
This library attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.
Getting Started
Create your own adapter
Create an adapter that implements the CacheAdapterInterface. A simple array adapter would look as follows. The array adapter is also shipped with this library.
<?php namespace My\Namespace; use Genkgo\Cache\CacheAdapterInterface; class ArrayAdapter implements CacheAdapterInterface { private $data = []; public function set($key, $value) { $this->data[$key] = $value; } public function get($key) { if ($this->exists($key)) { return $this->data[$key]; } } public function delete($key) { if ($this->exists($key)) { unset($this->data[$key]); } } private function exists($key) { return isset($this->data[$key]) || array_key_exists($key, $this->data); } }
Inject the adapter
To use your adapter, inject it into another object and start using the api. If you do not want any cache, but your class relies on a cache adapter being there, inject the NullAdapter.
Contributing
- Found a bug? Please try to solve it yourself first and issue a pull request. If you are not able to fix it, at least give a clear description what goes wrong. We will have a look when there is time.
- Want to see a feature added, issue a pull request and see what happens. You could also file a bug of the missing feature and we can discuss how to implement it.