2017 © Pedro Peláez
 

library zf-http-cache

ZF2 Module providing http cache headers support

image

zfcampus/zf-http-cache

ZF2 Module providing http cache headers support

  • Thursday, May 3, 2018
  • by zendframework
  • Repository
  • 9 Watchers
  • 6 Stars
  • 73,188 Installations
  • PHP
  • 2 Dependents
  • 3 Suggesters
  • 9 Forks
  • 0 Open issues
  • 12 Versions
  • 7 % Grown

The README.md

ZF Http Cache

Repository abandoned 2019-12-31

This repository has moved to laminas-api-tools/api-tools-http-cache., (*1)

Build Status Coverage Status, (*2)

Introduction

zf-http-cache is a ZF2 module for automating http-cache tasks within a Zend Framework 2 application., (*3)

Installation

Run the following composer command:, (*4)

$ composer require "zfcampus/zf-http-cache:^1.0"

Alternately, manually add the following to your composer.json, in the require section:, (*5)

"require": {
    "zfcampus/zf-http-cache": "^1.0"
}

And then run composer update to ensure the module is installed., (*6)

Finally, add the module name to your project's config/application.config.php under the modules key:, (*7)

return [
    /* ... */
    'modules' => [
        /* ... */
        'ZF\HttpCache',
    ],
    /* ... */
];

Configuration

User Configuration

As a rule of thumb, avoid as much as possible using anonymous functions since it prevents you from caching your configuration., (*8)

The top-level configuration key for user configuration of this module is zf-http-cache., (*9)

The config/module.config.php file contains a self-explanative example of configuration., (*10)

Key: controllers

The controllers key is utilized for mapping any of, (*11)

  • a route name
  • a concatenated controller::action
  • a controller
  • a regexp
  • a wildcard

Each is case sensitive, and will map one or more HTTP methods to the cache header configuration specific to the given rule., (*12)

Example:, (*13)

// See `config/module.config.php` for a complete commented example
'zf-http-cache' => [
    /* ... */
    'controllers' => [
        '<controller>' => [
            '<http-method>'  => [
                '<cache-header-name>' => [
                    'override' => true,
                    'value'    => '<cache-header-value>',
                ],
            ],
        ],
    ],
    /* ... */
],    
Key: <controller>

Either, (*14)

  • a concatenation of $controller::$action
  • a controller name (as returned by Zend\Mvc\MvcEvent::getRouteMatch()->getParam('controller'); the value is case-sensitive)
  • a regexp (see <regex_delimiter> key)
  • a wildcard

A wildcard matches any unspecified controllers., (*15)

Key: <http-method>

Either a lower cased HTTP method (get, post, etc.) (as returned by Zend\Http\Request::getMethod()) or a wildcard., (*16)

A wildcard stands for all the non-specified HTTP methods., (*17)

Key: <cache-header-name>

An HTTP cache header name (Cache-control, expires, etag etc.)., (*18)

ETags

For ETags you can specify a custom generator in the configuration:, (*19)

'etag' => [
    'override' => true,
    'generator' => 'Your\Own\ETagGenerator',
],

A generator example can be found in \ZF\HttpCache\DefaultETagGenerator., (*20)

Key: <cache-header-value>

The value for the cache header., (*21)

Key: override

Whether to override the cache headers possibly sent by your application., (*22)

Key: enable

The enable key is utilized for enabling/disabling the http cache module at run time., (*23)

If you no longer need this module, rather consider removing the module from the application.config.php list., (*24)

Caution: when disabled, http cache module doesn't override/remove the cache headers sent by your application., (*25)

Example:, (*26)

'zf-http-cache' => [
    /* ... */
    'enable' => true, // Cache module is enabled.
    /* ... */
],

Key: http_codes_black_list

The http_codes_black_list is utilized to avoid caching the responses with the listed HTTP status codes. Defaults to all others than 200., (*27)

Example:, (*28)

'zf-http-cache' => [
    /* ... */
    'http_codes_black_list' => ['201', '304', '400', '500'], // Whatever the other configurations, the responses with these HTTP codes won't be cached.
    /* ... */
],

Key: regex_delimiter

This key is used to enable the evaluation of the key as a regular expression., (*29)

It must contain the delimiter of the regular expression., (*30)

If you don't want to use regular expression in your configuration set this to null to avoid inutil parsing., (*31)

Regular expressions are tested in the very order they appear in the configuration, first matching wins., (*32)

Regexp wins over wildcard., (*33)

Caution: When this value is not empty and no litteral key corresponds to the current controller, a preg_match is used., (*34)

Example:, (*35)

'zf-http-cache' => [
    /* ... */
    'regex_delimiter' => '~',
    /* ... */
    'controllers' => [
        '~.*~' => [ // Acts as a wildcard.
            /* ... */
        ],
    ],
    /* ... */
],

System Configuration

The following configuration is provided in config/module.config.php:, (*36)

'service_manager' => [
    'factories' => [
        'ZF\HttpCache\HttpCacheListener' => 'ZF\HttpCache\HttpCacheListenerFactory',
    ],
],

ZF2 Events

Listeners

ZF\HttpCache\HttpCacheListener

This listener is attached to the MvcEvent::EVENT_ROUTE and MvcEvent::EVENT_FINISH events with the low priority of -10000., (*37)

The Versions

03/05 2018
03/05 2018
07/07 2016
06/07 2016

1.2.3

1.2.3.0 http://apigility.org/

ZF2 Module providing http cache headers support

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

api cache zf2 zend module apigility

10/11 2015

1.2.1

1.2.1.0 http://apigility.org/

ZF2 Module providing http cache headers support

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

api cache zf2 zend module apigility

10/11 2015

1.2.0

1.2.0.0 http://apigility.org/

ZF2 Module providing http cache headers support

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

api cache zf2 zend module apigility

15/07 2015

1.1.0

1.1.0.0 http://apigility.org/

ZF2 Module providing http cache headers support

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

api cache zf2 zend module apigility

14/07 2015

1.0.2

1.0.2.0 http://apigility.org/

ZF2 Module providing http cache headers support

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

api cache zf2 zend module apigility

24/10 2014

1.0.1

1.0.1.0

ZF2 Module providing http cache headers support

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache zf2 zend module

05/06 2014

1.0.0

1.0.0.0

ZF2 Module providing http cache headers support

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache zf2 zend module