clickalicious / cachingmiddleware
The PSR-7 middleware for caching compatible to PSR-6.
Installs: 1 100
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/clickalicious/cachingmiddleware
Requires
- php: >=5.5.0
- gpupo/cache: ^1.2
- psr/http-message: ^1.0
- shrikeh/teapot: ^1.0
- wandu/http: ^1.6
Requires (Dev)
- cocur/slugify: ^2.1
- phpunit/phpunit: ^4.8
- relay/relay: ^1.1
- symfony/var-dumper: ^2.8
This package is not auto-updated.
Last update: 2025-10-26 00:28:52 UTC
README
The PSR-7 middleware for caching compatible to PSR-6.
Table of Contents
Features
- Caching of almost any content produced in a PHP execution loop like PHP,HTML(...)
- Stackable into PSR-7stacks for easy integration
- Compatible to all PSR-6caching implementations and a lot of caching backends
- High performance (developed using a profiler)
- Lightweight and high-quality codebase (following PSR-1,2,4,7)
- 100% PSR-7middleware compatibility
- 100% PSR-6caching compatibility
- Clean & well documented code
- Unit-tested with a good coverage
Example
This is just a simple demonstration on how to get started using this middleware library in a very simple context. Put a Cache in queue and use a PSR-6 Cache (Filesystem as backend - but you could also use Redis, Memcached, MySQL or any other backend implemented a PSR-6 caching layer ...):
/** * Fill queue for running "Caching Middleware" * * @param \Psr\Http\Message\ServerRequestInterface $request Request (PSR) to process * @param \Psr\Http\Message\ResponseInterface $response Response (PSR) to use * @param callable $next Next middleware in stack * * @return \Psr\Http\Message\ResponseInterface A PSR compatible response */ $queue[] = function (Request $request, Response $response, callable $next) { // Create cache item factory $cacheItemFactory = function ($key) { return new CacheItem($key); }; // Create cache item key factory $cacheItemKeyFactory = function (Request $request) { static $key = null; if (null === $key) { $uri = $request->getUri(); $slugify = new Slugify(); $key = $slugify->slugify(trim($uri->getPath(), '/').($uri->getQuery() ? '?'.$uri->getQuery() : '')); } return $key; }; // Get cache $cachingMiddleWare = new Clickalicious\Caching\Middleware\Cache( new CacheItemPool('Filesystem'), $cacheItemFactory, $cacheItemKeyFactory ); return $cachingMiddleWare($request, $response, $next); };
Requirements
- PHP >= 5.6(compatible up to version- 7.2as well as- HHVM)
Philosophy
Caching Middleware is a PSR-7 compatible middleware based on PSR-6 compatible cache implementations. Caching Middleware isn't a unicorn - it's good but it maybe going to change with time. Try it, run it ... ♥ it ;)
Versioning
For a consistent versioning we decided to make use of Semantic Versioning 2.0.0 http://semver.org. Its easy to understand, very common and known from many other software projects.
Roadmap
- Cache whole response instead just rendered HTML (Headers as well for example)
-  Implement flysystem as Driver for PSR-Cache
Security Issues
If you encounter a (potential) security issue don't hesitate to get in contact with us opensource@clickalicious.de before releasing it to the public. So i get a chance to prepare and release an update before the issue is getting shared. Thank you!
Participate & Share
... yeah. If you're a code monkey too - maybe we can build a force ;) If you would like to participate in either Code, Comments, Documentation, Wiki, Bug-Reports, Unit-Tests, Bug-Fixes, Feedback and/or Critic then please let us know as well!
Sponsors
Thanks to our sponsors and supporters:
| JetBrains | Navicat | 
|---|---|
