PHPackages                             zfcampus/zf-http-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. zfcampus/zf-http-cache

Abandoned → [laminas-api-tools/api-tools-http-cache](/?search=laminas-api-tools%2Fapi-tools-http-cache)ArchivedLibrary[Caching](/categories/caching)

zfcampus/zf-http-cache
======================

ZF2 Module providing http cache headers support

1.4.0(8y ago)8251.0k↓15.8%5[1 PRs](https://github.com/zfcampus/zf-http-cache/pulls)1BSD-3-ClausePHPPHP ^5.6 || ^7.0

Since Jun 4Pushed 6y ago7 watchersCompare

[ Source](https://github.com/zfcampus/zf-http-cache)[ Packagist](https://packagist.org/packages/zfcampus/zf-http-cache)[ Docs](http://apigility.org/)[ RSS](/packages/zfcampus-zf-http-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (12)Used By (1)

ZF Http Cache
=============

[](#zf-http-cache)

> ## Repository abandoned 2019-12-31
>
> [](#repository-abandoned-2019-12-31)
>
> This repository has moved to [laminas-api-tools/api-tools-http-cache](https://github.com/laminas-api-tools/api-tools-http-cache).

[![Build Status](https://camo.githubusercontent.com/92266bb3d26b55d0b50443d52dfbbd8647912af173b880458715df4842c765c6/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f7a6663616d7075732f7a662d687474702d63616368652e7376673f6272616e63683d6d6173746572)](https://secure.travis-ci.org/zfcampus/zf-http-cache)[![Coverage Status](https://camo.githubusercontent.com/97ca5635a55f67bab955e6565e8a357df4c76f3fbf0061f1dbe631acafbb47d6/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7a6663616d7075732f7a662d687474702d63616368652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/zfcampus/zf-http-cache?branch=master)

Introduction
------------

[](#introduction)

`zf-http-cache` is a ZF2 module for automating http-cache tasks within a Zend Framework 2 application.

Installation
------------

[](#installation)

Run the following `composer` command:

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

Alternately, manually add the following to your `composer.json`, in the `require` section:

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

And then run `composer update` to ensure the module is installed.

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

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

Configuration
-------------

[](#configuration)

### User Configuration

[](#user-configuration)

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

The top-level configuration key for user configuration of this module is `zf-http-cache`.

The `config/module.config.php` file contains a self-explanative example of configuration.

#### Key: `controllers`

[](#key-controllers)

The `controllers` key is utilized for mapping any of

- 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.

Example:

```
// See `config/module.config.php` for a complete commented example
'zf-http-cache' => [
    /* ... */
    'controllers' => [
        '' => [
            ''  => [
                '' => [
                    'override' => true,
                    'value'    => '',
                ],
            ],
        ],
    ],
    /* ... */
],
```

##### Key: ``

[](#key-controller)

Either

- 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 `` key)
- a wildcard

A wildcard matches any unspecified controllers.

##### Key: ``

[](#key-http-method)

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

A wildcard stands for all the non-specified HTTP methods.

##### Key: ``

[](#key-cache-header-name)

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

###### ETags

[](#etags)

For ETags you can specify a custom generator in the configuration:

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

```

A generator example can be found in `\ZF\HttpCache\DefaultETagGenerator`.

##### Key: ``

[](#key-cache-header-value)

The value for the cache header.

##### Key: `override`

[](#key-override)

Whether to override the cache headers possibly sent by your application.

#### Key: `enable`

[](#key-enable)

The `enable` key is utilized for enabling/disabling the http cache module at run time.

If you no longer need this module, rather consider removing the module from the `application.config.php` list.

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

Example:

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

#### Key: `http_codes_black_list`

[](#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`.

Example:

```
'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`

[](#key-regex_delimiter)

This key is used to enable the evaluation of the key as a regular expression.

It must contain the delimiter of the regular expression.

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

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

Regexp wins over wildcard.

**Caution: When this value is not empty and no litteral key corresponds to the current controller, a preg\_match is used.**

Example:

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

### System Configuration

[](#system-configuration)

The following configuration is provided in `config/module.config.php`:

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

ZF2 Events
----------

[](#zf2-events)

### Listeners

[](#listeners)

#### `ZF\HttpCache\HttpCacheListener`

[](#zfhttpcachehttpcachelistener)

This listener is attached to the `MvcEvent::EVENT_ROUTE` and `MvcEvent::EVENT_FINISH` events with the low priority of `-10000`.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 77.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~158 days

Recently: every ~226 days

Total

10

Last Release

2937d ago

PHP version history (3 changes)1.0.0PHP &gt;=5.3.23

1.2.0PHP ^5.5|^7.0

1.3.0PHP ^5.6 || ^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/296074?v=4)[Zend Framework](/maintainers/zendframework)[@zendframework](https://github.com/zendframework)

---

Top Contributors

[![weierophinney](https://avatars.githubusercontent.com/u/25943?v=4)](https://github.com/weierophinney "weierophinney (95 commits)")[![adri](https://avatars.githubusercontent.com/u/133832?v=4)](https://github.com/adri "adri (17 commits)")[![corentin-larose](https://avatars.githubusercontent.com/u/1617965?v=4)](https://github.com/corentin-larose "corentin-larose (5 commits)")[![Maks3w](https://avatars.githubusercontent.com/u/1301698?v=4)](https://github.com/Maks3w "Maks3w (4 commits)")[![robertmarsal](https://avatars.githubusercontent.com/u/507871?v=4)](https://github.com/robertmarsal "robertmarsal (1 commits)")

---

Tags

apizendcacheZendFrameworkzfmoduleapigility

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zfcampus-zf-http-cache/health.svg)

```
[![Health](https://phpackages.com/badges/zfcampus-zf-http-cache/health.svg)](https://phpackages.com/packages/zfcampus-zf-http-cache)
```

###  Alternatives

[stroker/cache

Provides a full page cache solution for Laminas

6444.7k](/packages/stroker-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
