PHPackages                             juliangut/cacheware - 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. juliangut/cacheware

ActiveLibrary[Caching](/categories/caching)

juliangut/cacheware
===================

PSR7 cache headers management middleware

1.1(9y ago)039BSD-3-ClausePHPPHP &gt;=5.5

Since May 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/juliangut/cacheware)[ Packagist](https://packagist.org/packages/juliangut/cacheware)[ Docs](https://github.com/juliangut/cacheware)[ RSS](/packages/juliangut-cacheware/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (9)Versions (4)Used By (0)

[![PHP version](https://camo.githubusercontent.com/8c508dbfb530cc5703d088796f65f3230e83d32a68e84c73bc9e7847b12a0fa7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344352e352d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net)[![Latest Version](https://camo.githubusercontent.com/fb8dd3aa92007b0b1da5e81d2505546d04876691cebce652e77a3c7207fd1e40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6a756c69616e6775742f6361636865776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/cacheware)[![License](https://camo.githubusercontent.com/f308ee14f17cf8fa971a1ac643642da3d0c8a09f5e0acb53bfb0bd7acaeb1851/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a756c69616e6775742f6361636865776172652e7376673f7374796c653d666c61742d737175617265)](https://github.com//cacheware/blob/master/LICENSE)

[![Build status](https://camo.githubusercontent.com/2373912234937de5189fd1d57ad7b40555396ac9072d9abc5476131465c36d13/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a756c69616e6775742f6361636865776172652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/juliangut/cacheware)[![Style](https://camo.githubusercontent.com/e0b4fbaf65049dc2aa28e9f97658fa2883f20fb40e116dcc15ce783a123830e2/68747470733a2f2f7374796c6563692e696f2f7265706f732f35393431383938372f736869656c64)](https://styleci.io/repos/59418987)[![Code Quality](https://camo.githubusercontent.com/217dce1f03f751ec713f9b578f6bfa99c6ddb11a163e8df9e6d932f8fe144de1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a756c69616e6775742f6361636865776172652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/juliangut/cacheware)[![Code Coverage](https://camo.githubusercontent.com/84139dfde27d71d5fdad05cacd1f0c912c5c67876c469b6b1e51f34d07c5a136/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a756c69616e6775742f6361636865776172652e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/juliangut/cacheware)[![Total Downloads](https://camo.githubusercontent.com/a24816129bf5edb7cdb32342f54282ec83ab429f1ea549c7b8e8db2cfb4b90e1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a756c69616e6775742f6361636865776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/cacheware)

CacheWare
=========

[](#cacheware)

A PSR7 cache headers management middleware.

This middleware must be run *before* `session_start` has been called so it can prevent PHP session mechanism from automatically send any kind of header to the client (including session cookie and caching).

> You can use this middleware with [juliangut/sessionware](https://github.com/juliangut/sessionware) which will automatically handle session management.

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

[](#installation)

### Composer

[](#composer)

```
composer require juliangut/cacheware

```

Usage
-----

[](#usage)

```
require 'vendor/autoload.php';

use \Jgut\Middleware\CacheWare

$configuration = [
  'limiter' => 'private',
  'expire' => 1800, // 30 minutes
];

$cacheMiddleware = new CacheWare($configuration);

// Get $request and $response from PSR7 implementation
$request = new Request();
$response = new Response();

$response = $cacheMiddleware($request, $response, function() { });

// Response has corresponding cache headers for private cache
```

Integrated on a Middleware workflow:

```
require 'vendor/autoload.php';

use \Jgut\Middleware\CacheWare

$app = new \YourMiddlewareAwareApplication();
$app->addMiddleware(new CacheWare(['limiter' => 'nocache']));
$app->run();
```

### Config

[](#config)

```
$cacheMiddleware = new CacheWare([
  'limiter' => null
  'expire' => 180,
]);
```

#### limiter

[](#limiter)

Selects cache limiter type. It's values can be `public`, `private`, `private_no_expire` or `nocache`. If not provided value defined in ini\_set `session.cache_limiter` will be automatically used (normally 'nocache').

Cacheware class has CACHE\_\* constants for convenience.

If you want to completely disable cache headers give limiter a value of `null`.

#### expire

[](#expire)

Sets the time in seconds for caching. If not provided value defined in ini\_set `session.cache_expire` will be automatically used (normally 180). This setting is ignore when using `nocache` limiter.

Contributing
------------

[](#contributing)

Found a bug or have a feature request? [Please open a new issue](https://github.com/juliangut/cacheware/issues). Have a look at existing issues before.

See file [CONTRIBUTING.md](https://github.com/juliangut/cacheware/blob/master/CONTRIBUTING.md)

License
-------

[](#license)

See file [LICENSE](https://github.com/juliangut/cacheware/blob/master/LICENSE) included with the source code for a copy of the license terms.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~58 days

Total

3

Last Release

3574d ago

Major Versions

0.1 → 1.02016-06-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c50421f1ab4148354dc2dd5dcaba168656b17ea913b310d112deb39a6f73ca1?d=identicon)[juliangut](/maintainers/juliangut)

---

Top Contributors

[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (5 commits)")

---

Tags

middlewarepsr7cache

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/juliangut-cacheware/health.svg)

```
[![Health](https://phpackages.com/badges/juliangut-cacheware/health.svg)](https://phpackages.com/packages/juliangut-cacheware)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k34](/packages/neuron-core-neuron-ai)[kevinrob/guzzle-cache-middleware

A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)

43518.2M126](/packages/kevinrob-guzzle-cache-middleware)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35729.6k2](/packages/telnyx-telnyx-php)[eliashaeussler/cache-warmup

Composer package to warm up website caches, based on a given XML sitemap

75419.2k9](/packages/eliashaeussler-cache-warmup)[flc/laravel-middleware-cache-response

Laravel中间件-Response缓存

608.2k](/packages/flc-laravel-middleware-cache-response)

PHPackages © 2026

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