PHPackages                             laminas-api-tools/api-tools-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. laminas-api-tools/api-tools-http-cache

ActiveLibrary[Caching](/categories/caching)

laminas-api-tools/api-tools-http-cache
======================================

Laminas Module providing http cache headers support

1.6.0(4y ago)582.6k↓26.2%6[1 issues](https://github.com/laminas-api-tools/api-tools-http-cache/issues)[2 PRs](https://github.com/laminas-api-tools/api-tools-http-cache/pulls)1BSD-3-ClausePHPPHP ^7.3 || ~8.0.0 || ~8.1.0CI passing

Since Dec 31Pushed 3mo ago9 watchersCompare

[ Source](https://github.com/laminas-api-tools/api-tools-http-cache)[ Packagist](https://packagist.org/packages/laminas-api-tools/api-tools-http-cache)[ Docs](https://api-tools.getlaminas.org)[ Fund](https://funding.communitybridge.org/projects/laminas-project)[ RSS](/packages/laminas-api-tools-api-tools-http-cache/feed)WikiDiscussions 1.7.x Synced 1mo ago

READMEChangelog (2)Dependencies (9)Versions (17)Used By (1)

Laminas Http Cache
==================

[](#laminas-http-cache)

[![Build Status](https://github.com/laminas-api-tools/api-tools-http-cache/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/laminas-api-tools/api-tools-http-cache/actions/workflows/continuous-integration.yml)

> ## 🇷🇺 Русским гражданам
>
> [](#-русским-гражданам)
>
> Мы, участники Laminas, родились и живем в разных странах. У многих из нас есть друзья, родственники и коллеги как в России, так и в Украине. Некоторые из нас родились в России. Некоторые из нас живут в России. У некоторых бабушки и дедушки сражались с фашистами во Второй мировой войне. Здесь никто не поддерживает фашизм.
>
> У одного из нас есть украинская родственница, которая спаслась из дома вместе с сыном. Поезд задержался из-за бомбежки на дороге впереди. У нас есть друзья, которые прячутся в бомбоубежищах. Мы с тревогой ждем весточки от них после воздушных налетов, которые беспорядочно наносят удары и попадают по больницам, школам, детским садам и домам. Мы не берем это из каких-либо СМИ. Мы наблюдаем это напрямую.
>
> Вы доверяете нам достаточно, чтоб использовать наши программы, и мы просим вас довериться нам вновь. Мы нуждаемся в помощи. Выходите и протестуйте против этой бесполезной войны. Остановите кровопролитие. Скажите "Нет войне!"
>
> ## 🇺🇸 To Citizens of Russia
>
> [](#-to-citizens-of-russia)
>
> We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
>
> One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
>
> You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"

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

[](#introduction)

`api-tools-http-cache` is a Laminas module for automating http-cache tasks within a Laminas application.

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

[](#installation)

Run the following `composer` command:

```
$ composer require "laminas-api-tools/api-tools-http-cache:^1.0"
```

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

```
"require": {
    "laminas-api-tools/api-tools-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' => [
        /* ... */
        'Laminas\ApiTools\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 `api-tools-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
'api-tools-http-cache' => [
    /* ... */
    'controllers' => [
        '' => [
            ''  => [
                '' => [
                    'override' => true,
                    'value'    => '',
                ],
            ],
        ],
    ],
    /* ... */
],
```

##### Key: ``

[](#key-controller)

Either

- a concatenation of `$controller::$action`
- a controller name (as returned by `Laminas\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 `Laminas\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 `\Laminas\ApiTools\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:

```
'api-tools-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:

```
'api-tools-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:

```
'api-tools-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' => [
        'Laminas\ApiTools\HttpCache\HttpCacheListener' => 'Laminas\ApiTools\HttpCache\HttpCacheListenerFactory',
    ],
],
```

Laminas Events
--------------

[](#laminas-events)

### Listeners

[](#listeners)

#### `Laminas\ApiTools\HttpCache\HttpCacheListener`

[](#laminasapitoolshttpcachehttpcachelistener)

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

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance49

Moderate activity, may be stable

Popularity36

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 67.1% 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 ~53 days

Recently: every ~68 days

Total

16

Last Release

1532d ago

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

1.2.0PHP ^5.5 || ^7.0

1.3.0PHP ^5.6 || ^7.0

1.5.0PHP ^7.3 || ~8.0.0

1.6.0PHP ^7.3 || ~8.0.0 || ~8.1.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25943?v=4)[Matthew Weier O'Phinney](/maintainers/weierophinney)[@weierophinney](https://github.com/weierophinney)

![](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 (102 commits)")[![adri](https://avatars.githubusercontent.com/u/133832?v=4)](https://github.com/adri "adri (17 commits)")[![michalbundyra](https://avatars.githubusercontent.com/u/7423207?v=4)](https://github.com/michalbundyra "michalbundyra (13 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)")[![snapshotpl](https://avatars.githubusercontent.com/u/312655?v=4)](https://github.com/snapshotpl "snapshotpl (3 commits)")[![geerteltink](https://avatars.githubusercontent.com/u/9497586?v=4)](https://github.com/geerteltink "geerteltink (3 commits)")[![boesing](https://avatars.githubusercontent.com/u/2189546?v=4)](https://github.com/boesing "boesing (2 commits)")[![robertmarsal](https://avatars.githubusercontent.com/u/507871?v=4)](https://github.com/robertmarsal "robertmarsal (1 commits)")[![paresh27](https://avatars.githubusercontent.com/u/25386515?v=4)](https://github.com/paresh27 "paresh27 (1 commits)")[![alexdenvir](https://avatars.githubusercontent.com/u/1412074?v=4)](https://github.com/alexdenvir "alexdenvir (1 commits)")

---

Tags

hacktoberfestapilaminascachemoduleapi-tools

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/laminas-api-tools-api-tools-http-cache/health.svg)

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

PHPackages © 2026

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