morphable / simple-cache
A simple cache component, easy to implement into any system
1.0.4-stable
2019-11-17 19:11 UTC
Requires
- php: ~7.0
Requires (Dev)
- phpunit/phpunit: >=5.4.3
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2024-12-18 06:54:09 UTC
README
A simple cache component, easy to implement into any system
Installing
$ composer require morphable/simple-cache
Usage
<?php use \Morphable\SimpleCache; // cache dir $cache = new SimpleCache($root . '/.cache'); $cache->set('my_cache_item', $cacheItem); $cache->exists('my_cache_item'); // true $cache->get('my_cache_item'); $cache->delete('my_cache_item');
Create your own content serializer
<?php use \Morphable\SimpleCache\Exception\UnableToSerialize; use \Morphable\SimpleCache\Exception\UnableToUnserialize; use \Morphable\SimpleCache\SerializeInterface; class MySerializer implements SerializeInterface { public function serialize(array $content): string { } public function unserialize(string $content): array { } }
Use it like this:
use \Morphable\SimpleCache; $serializer = new MySerializer(); $cache = new SimpleCache($root . '/.cache', $serializer);
Contributing
- Follow PSR-2 and the .editorconfig
- Start namespaces with \Morphable\SimpleCache
- Make tests