lss / yacache
Lightweight Cache (PSR-16 compatible)
1.2.0
2020-12-03 21:41 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- ext-apcu: *
- ext-redis: *
- nesbot/carbon: ^2.41
- phpstan/phpstan: ^0.12.28
- phpstan/phpstan-phpunit: ^0.12.11
- phpstan/phpstan-strict-rules: ^0.12.2
- phpunit/phpunit: ^9.2
README
A minimal PSR16 compatible cache library for PHP 7.4+
The goals of this project are
- Minimalism: as little code as possible, only the barest necessary features, as few dependencies as possible.
- Performance: Strips out all but essential features in the main execution flow so that it runs really fast.
- (almost) Standards Compliance: PSR-16 does not have strict typing (yet!?).
The
CacheInterface
is mostly duck-type compatible with PSR-16 (No support for DateInterval $ttl) - adds some tiny and optional utility functions to ease API development eg
increment()
for rate limiters,remember()
to remove boilerplate lines of code - Quality: 100% unit test coverage, phpstan max strict, strict_types=1
Why another cache when there are already so many that are very good?
- https://github.com/desarrolla2/Cache is lean and clean but has extra tools for Packing (serialisation)
- https://github.com/terrylinooo/simple-cache has tons of drivers, but an extra layer of indirection (
do*
methods) - many other caches (eg https://github.com/symfony/cache) work with PSR-6 (which is very heavy) and then add adapters / wrappers for PSR-16 on top
- ... or their code has stampede protection or other clever but complicated things which are awesome for bigger projects (with more traffic) but way overkill for small stuff.
Pull requests welcome, but bear in mind the above project goals. If you have more complex needs, the other (better written, better supported, more mature) projects mentioned above will be a better choice for you.
Installation
composer require LSS\YACache
How to use
use LSS\YACache\RedisCache; $redis = new \Redis('127.0.0.1'); $cache = new RedisCache($redis); $value = $cache->remember('another key', 100, function () use ($database) { return $database->someExpensiveQueryResult(); });
Browse the /src
directory for more drivers