PHPackages                             guzzlehttp/cache-subscriber - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. guzzlehttp/cache-subscriber

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

guzzlehttp/cache-subscriber
===========================

Guzzle HTTP cache subscriber

0.2.0(6y ago)631.3M↑17.6%2810MITPHPPHP &gt;=5.4.0

Since Oct 29Pushed 6y ago3 watchersCompare

[ Source](https://github.com/guzzle/cache-subscriber)[ Packagist](https://packagist.org/packages/guzzlehttp/cache-subscriber)[ Docs](http://guzzlephp.org/)[ RSS](/packages/guzzlehttp-cache-subscriber/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (10)

Guzzle Cache Subscriber
=======================

[](#guzzle-cache-subscriber)

Important

**This repo has not been updated for Guzzle 6 and only supports Guzzle 5.**

See  for a nice Guzzle 6 compatible Cache middleware.

Provides a private transparent proxy cache for caching HTTP responses.

Here's a simple example of how it's used:

```
use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Cache\CacheSubscriber;

$client = new Client(['defaults' => ['debug' => true]]);

// Use the helper method to attach a cache to the client.
CacheSubscriber::attach($client);

// Send the first request
$a = $client->get('http://en.wikipedia.org/wiki/Main_Page');

// Send the second request. This will find a cache hit which must be
// validated. The validation request returns a 304, which yields the original
// cached response.
$b = $client->get('http://en.wikipedia.org/wiki/Main_Page');
```

Running the above code sample should output verbose cURL information that looks something like this:

```
> GET /wiki/Main_Page HTTP/1.1
Host: en.wikipedia.org
User-Agent: Guzzle/4.2.1 curl/7.37.0 PHP/5.5.13
Via: 1.1 GuzzleCache/4.2.1

< HTTP/1.1 200 OK
< Server: Apache
< X-Content-Type-Options: nosniff
< Content-language: en
< X-UA-Compatible: IE=Edge
< Vary: Accept-Encoding,Cookie
< Last-Modified: Thu, 21 Aug 2014 01:51:49 GMT
< Content-Type: text/html; charset=UTF-8
< X-Varnish: 2345493325, 1998949714 1994269567
< Via: 1.1 varnish, 1.1 varnish
< Transfer-Encoding: chunked
< Date: Thu, 21 Aug 2014 02:34:12 GMT
< Age: 2541
< Connection: keep-alive
< X-Cache: cp1055 hit (1), cp1068 frontend hit (25353)
< Cache-Control: private, s-maxage=0, max-age=0, must-revalidate
< Set-Cookie: GeoIP=US:Seattle:47.6062:-122.3321:v4; Path=/; Domain=.wikipedia.org
<
* Connection #0 to host en.wikipedia.org left intact
* Re-using existing connection! (#0) with host en.wikipedia.org
> GET /wiki/Main_Page HTTP/1.1
Host: en.wikipedia.org
User-Agent: Guzzle/4.2.1 curl/7.37.0 PHP/5.5.13
Via: 1.1 GuzzleCache/4.2.1, 1.1 GuzzleCache/4.2.1
If-Modified-Since: Thu, 21 Aug 2014 01:51:49 GMT

< HTTP/1.1 304 Not Modified
< Server: Apache
< X-Content-Type-Options: nosniff
< Content-language: en
< X-UA-Compatible: IE=Edge
< Vary: Accept-Encoding,Cookie
< Last-Modified: Thu, 21 Aug 2014 01:51:49 GMT
< Content-Type: text/html; charset=UTF-8
< X-Varnish: 2345493325, 1998950450 1994269567
< Via: 1.1 varnish, 1.1 varnish
< Date: Thu, 21 Aug 2014 02:34:12 GMT
< Age: 2541
< Connection: keep-alive
< X-Cache: cp1055 hit (1), cp1068 frontend hit (25360)
< Cache-Control: private, s-maxage=0, max-age=0, must-revalidate
< Set-Cookie: GeoIP=US:Seattle:47.6062:-122.3321:v4; Path=/; Domain=.wikipedia.org
<
* Connection #0 to host en.wikipedia.org left intact
```

Installing
----------

[](#installing)

Add the following to your composer.json:

```
{
    "require": {
        "guzzlehttp/cache-subscriber": "0.2.*@dev"
    }
}
```

or

```
$ composer require guzzlehttp/cache-subscriber
```

Creating a CacheSubscriber
--------------------------

[](#creating-a-cachesubscriber)

The easiest way to create a CacheSubscriber is using the `attach()` helper method of `GuzzleHttp\Subscriber\Cache\CacheSubscriber`. This method accepts a request or client object and attaches the necessary subscribers used to perform cache lookups, validation requests, and automatic purging of resources.

The `attach()` method accepts the following options:

storageA `GuzzleHttp\Subscriber\Cache\CacheStorageInterface` object used to store cached responses. If no value is not provided, an in-memory array cache will be used.validateA Boolean value that determines if cached response are ever validated against the origin server. This setting defaults to `true` but can be disabled by passing `false`.purgeA Boolean value that determines if cached responses are purged when non-idempotent requests are sent to their URI. This setting defaults to `true` but can be disabled by passing `false`.can\_cacheAn optional callable used to determine if a request can be cached. The callable accepts a `GuzzleHttp\Message\RequestInterface` and returns a Boolean value. If no value is provided, the default behavior is utilized.Warning

This is a WIP update for Guzzle 5+. It hasn't been tested and is in active development. Expect bugs and breaks.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community33

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.4% 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 ~1782 days

Total

2

Last Release

2458d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/190930?v=4)[Michael Dowling](/maintainers/mtdowling)[@mtdowling](https://github.com/mtdowling)

![](https://www.gravatar.com/avatar/0e4e105cea62b616d4cb376b08a849b6a428f646998537de150d16a8eb537b90?d=identicon)[mark.sagikazar](/maintainers/mark.sagikazar)

![](https://www.gravatar.com/avatar/d10b19f74fa2f712a4fbb9d9073c95d612c0f32e6ba95aed6f68e589c8e2688e?d=identicon)[Tobion](/maintainers/Tobion)

---

Top Contributors

[![mtdowling](https://avatars.githubusercontent.com/u/190930?v=4)](https://github.com/mtdowling "mtdowling (55 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (20 commits)")[![deviantintegral](https://avatars.githubusercontent.com/u/255023?v=4)](https://github.com/deviantintegral "deviantintegral (10 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (5 commits)")[![alcohol](https://avatars.githubusercontent.com/u/21414?v=4)](https://github.com/alcohol "alcohol (4 commits)")[![fire015](https://avatars.githubusercontent.com/u/501743?v=4)](https://github.com/fire015 "fire015 (3 commits)")[![bmancone](https://avatars.githubusercontent.com/u/2864622?v=4)](https://github.com/bmancone "bmancone (3 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (2 commits)")[![Progi1984](https://avatars.githubusercontent.com/u/1533248?v=4)](https://github.com/Progi1984 "Progi1984 (1 commits)")[![siwinski](https://avatars.githubusercontent.com/u/1034024?v=4)](https://github.com/siwinski "siwinski (1 commits)")[![skomov](https://avatars.githubusercontent.com/u/854589?v=4)](https://github.com/skomov "skomov (1 commits)")

---

Tags

Guzzlecache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/guzzlehttp-cache-subscriber/health.svg)

```
[![Health](https://phpackages.com/badges/guzzlehttp-cache-subscriber/health.svg)](https://phpackages.com/packages/guzzlehttp-cache-subscriber)
```

###  Alternatives

[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)

43418.2M126](/packages/kevinrob-guzzle-cache-middleware)[guzzlehttp/oauth-subscriber

Guzzle OAuth 1.0 subscriber

24015.1M149](/packages/guzzlehttp-oauth-subscriber)[graham-campbell/guzzle-factory

Provides A Simple Guzzle Factory With Good Defaults

936.8M53](/packages/graham-campbell-guzzle-factory)[bilfeldt/laravel-http-client-logger

A logger for the Laravel HTTP Client

1531.7M3](/packages/bilfeldt-laravel-http-client-logger)[hamburgscleanest/guzzle-advanced-throttle

A Guzzle middleware that can throttle requests according to (multiple) defined rules. It is also possible to define a caching strategy, e.g. get response from cache when rate limit is exceeded or always get cached value to spare your rate limits.

13033.4k1](/packages/hamburgscleanest-guzzle-advanced-throttle)[eljam/guzzle-jwt-middleware

A jwt authentication middleware for guzzle 6

28750.0k3](/packages/eljam-guzzle-jwt-middleware)

PHPackages © 2026

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