PHPackages                             aklump/slim-response-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. aklump/slim-response-cache

ActiveLibrary[Caching](/categories/caching)

aklump/slim-response-cache
==========================

Slim middleware for caching responses for subsequent requests.

0.2.1(6y ago)026BSD-3-ClausePHP

Since May 14Pushed 6y ago1 watchersCompare

[ Source](https://github.com/aklump/slim-response-cache)[ Packagist](https://packagist.org/packages/aklump/slim-response-cache)[ Docs](https://github.com/aklump/slim-response-cache)[ RSS](/packages/aklump-slim-response-cache/feed)WikiDiscussions master Synced yesterday

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

Response Cache Middleware
=========================

[](#response-cache-middleware)

Summary
-------

[](#summary)

This project provides a means of caching responses so that subsequent requests do not pass through the route callbacks. It is helpful if the route callbacks involve expensive calculations to generate content. It is built on the [HTTP Caching middleware](http://www.slimframework.com/docs/v3/features/caching.html) and should be used instead of that middleware. It ships with a file-based cache storage, but supports other types of caching via `\AKlump\Slim\Middleware\ContentCacheInterface`.

Quick Start
-----------

[](#quick-start)

```
$container = $app->getContainer();
$container['cache'] = function () {
  return new \Slim\HttpCache\CacheProvider();
};
$container['response_cache'] = function () {
  return new \AKlump\Slim\Middleware\FileCache('/path/to/cache/dir');
};

// Register this middleware.
$app->add(new \AKlump\Slim\Middleware\ContentCache($container['cache'], $container['response_cache'], 3600));

```

Requirements
------------

[](#requirements)

1. The response body must be able to be cast to a string.

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

[](#contributing)

If you find this project useful... please consider [making a donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4E5KZHDQCEUV8&item_name=Gratitude%20for%20aklump%2Fslim-response-cache).

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

[](#installation)

1. This middleware replaces [HTTP Caching](http://www.slimframework.com/docs/v3/features/caching.html) therefore you should not add that middleware as shown in those instructions. **Do not do the following:**

    ```
     $app->add(new \Slim\HttpCache\Cache('public', 86400));

    ```
2. However, you will need to register the service provider from that middleware as shown in the *Quick Start* above.

Advanced Usage
--------------

[](#advanced-usage)

### How do I alter the body prior to caching?

[](#how-do-i-alter-the-body-prior-to-caching)

If you want to alter the response body content before it is written to cache use the fourth argument callback as shown below, which adds a last modified note

```
$app->add(new \AKlump\Slim\Middleware\ContentCache(
  $container['cache'],
  $container['response_cache'],
  3600,
  function (\DateTime $modified, $html_body) use ($settings) {
    return $html_body . sprintf("Last modified: %s', $modified->format('r'));
  }
));

```

### How do I use a database for caching content?

[](#how-do-i-use-a-database-for-caching-content)

You may write your own class that implements `\AKlump\Slim\Middleware\ContentCacheInterface`.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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 ~1 days

Total

3

Last Release

2553d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79476f3b82f9c766433c7eb401cbcfc636cd5d5ccf2b2e6b50ea81d1de6c2730?d=identicon)[aklump](/maintainers/aklump)

---

Top Contributors

[![aklump](https://avatars.githubusercontent.com/u/425737?v=4)](https://github.com/aklump "aklump (18 commits)")

### Embed Badge

![Health badge](/badges/aklump-slim-response-cache/health.svg)

```
[![Health](https://phpackages.com/badges/aklump-slim-response-cache/health.svg)](https://phpackages.com/packages/aklump-slim-response-cache)
```

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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