Name: cache
Owner: Middlewares
Description: PSR-15 middleware with various cache utilities
Created: 2016-10-03 08:37:57.0
Updated: 2018-04-12 14:41:16.0
Pushed: 2018-01-25 21:46:05.0
Homepage: null
Size: 31
Language: PHP
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Middleware components with the following cache utilities:
This package is installable and autoloadable via Composer as middlewares/cache.
oser require middlewares/cache
To add the response headers for cache prevention. Useful in development environments:
patcher = new Dispatcher([
new Middlewares\CachePrevention()
ponse = $dispatcher->dispatch(new ServerRequest());
To add the Expires
and Cache-Control: max-age
headers to the response.
__construct(array $expires = null)
Set the available expires for each mimetype. If it's not defined, use the defaults.
defaultExpires(string $expires)
Set the default expires value if the request mimetype does not match. By default is 1 month. Example:
patcher = new Dispatcher([
(new Middlewares\Expires([ //set 1 year lifetime to css and js
'text/css' => '+1 year',
'text/javascript' => '+1 year',
]))->defaultExpires('+1 hour') //and 1 hour to everything else
ponse = $dispatcher->dispatch(new ServerRequest());
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.
__construct(Psr\Cache\CacheItemPoolInterface $cache)
The cache pool instance used to save the responses headers.
patcher = new Dispatcher([
new Middlewares\Cache($cache),
new Middlewares\Expires()
ponse = $dispatcher->dispatch(new ServerRequest());
Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.