Middleware with various cache utilities
Middleware components with the following cache utilities:
- PHP >= 7.0
- A PSR-7 http message implementation (Diactoros, Guzzle, Slim, etc...)
- A PSR-15 middleware dispatcher
This package is installable and autoloadable via Composer as middlewares/cache.
composer require middlewares/cache
To add the response headers for cache prevention. Useful in development environments:
$dispatcher = new Dispatcher([ new Middlewares\CachePrevention() ]); $response = $dispatcher->dispatch(new ServerRequest());
To add the
Cache-Control: max-age headers to the response.
Set the available expires for each mimetype. If it's not defined, use the defaults.
Set the default expires value if the request mimetype does not match. By default is 1 month. Example:
Saves the response headers in a PSR-6 cache pool and returns
304 responses (Not modified) if the response is still valid. This saves server resources and bandwidth because the body is returned empty. It's recomended to combine it with
Expires to set the lifetime of the responses.
The cache pool instance used to save the responses headers.
$dispatcher = new Dispatcher([ new Middlewares\Cache($cache), new Middlewares\Expires() ]); $response = $dispatcher->dispatch(new ServerRequest());
A PSR-17 factory to create the
The MIT License (MIT). Please see LICENSE for more information.