middlewares/cache

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

middlewares/cache

Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

Middleware components with the following cache utilities:

Requirements
Installation

This package is installable and autoloadable via Composer as middlewares/cache.

oser require middlewares/cache
CachePrevention

To add the response headers for cache prevention. Useful in development environments:

patcher = new Dispatcher([
new Middlewares\CachePrevention()


ponse = $dispatcher->dispatch(new ServerRequest());
Expires

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());
Cache

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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.