PHPackages                             snicholson/slimfilecache - 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. snicholson/slimfilecache

ActiveLibrary[Caching](/categories/caching)

snicholson/slimfilecache
========================

A file based cache middleware for the slim framework (3.0)

1.0.3(8y ago)117.0k5[2 issues](https://github.com/SamNicholson/slimfilecache/issues)apache 2.0PHP

Since Oct 4Pushed 8y ago3 watchersCompare

[ Source](https://github.com/SamNicholson/slimfilecache)[ Packagist](https://packagist.org/packages/snicholson/slimfilecache)[ RSS](/packages/snicholson-slimfilecache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Slim File Cache
===============

[](#slim-file-cache)

A file based cache middleware for the slim framework (3.0). The cache is a simple file based cache, I needed something for a very specific situation where I had many external API requests (essentially an API aggregator) to make and within a given time period they always made my routes give the same output. I didn't need a database or anything fancy, and wasn't too fussed about performance. So a file based cache made a lot of sense.

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

[](#installation)

Installation is done via composer

```
composer require snicholson/slimfilecache "~1.0"
```

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

[](#requirements)

This middleware works with slim 3.0 Release Candidate.

Setup
-----

[](#setup)

The middleware conforms to slims normal injection requirements. The example below is the basic setup of the cache. Once this has been implemented, it will automatically load any active cache records for the route currently being called and halt the execution of the application.

```
//Start up a new slim app
$slim = new App($container);

// Add file cache middleware
$cache = new \SNicholson\SlimFileCache\Cache($slim);
$slim->add($cache);
```

Usage
-----

[](#usage)

To use the cache you simple need to cache the output of your route before returning it. The add method takes up to 6 arguments, the first one is the route name. The second one is the content, and the third argument is the response code status (e.g. 200) and fourthly is an array of headers to send, the fifth is the duration of the cache in seconds. The default length is 1 hour. The second argument for the cache is the directory to store the cache files in. The directory must be writeable to the web user.

```
//Start up a new slim app
$slim = new App($container);

// Add file cache middleware
$cache = new \SNicholson\SlimFileCache\Cache($slim, 'relate/path/to/cache/directory');
$slim->add($cache);

//Configure the "foo" route and cache the output
$slim->get(
    '/foo',
    function(\Slim\Http\Request $request, \Slim\Http\Response $response, $args) use ($cache) {
      $response = 'foo response string';
      $cache->add('/foo', $response);
      return $response;
    }
);
```

Alternatively you can tell the cache to store all routes called by simple placing the following line after you have run the slim app

```
//Run the slim app (like normal)
$slim->run();

//Place the global cache afterwards, the next request at this route will be cached
$cache->add($slim->request->getUri()->getPath(), $slim->response->getBody()->__toString());
```

The cache has a few other simple methods. They are flush, get, remove. They essentially do what they say on the tin:

```
$cache = new \SNicholson\SlimFileCache\Cache($slim)

//Flush removes all entries
$cache->flush();

//Remove a single cache entry
$cache->remove('/foo');

//Get returns what is stored in the cache
$response = $cache->get('/foo');
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 96.7% 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 ~199 days

Total

4

Last Release

3282d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/46399f5ed7a2433a8b13df9bc3298329ba2f7e321c498463d0cf1653de7ac7d8?d=identicon)[SamNicholson](/maintainers/SamNicholson)

---

Top Contributors

[![SamNicholson](https://avatars.githubusercontent.com/u/9439200?v=4)](https://github.com/SamNicholson "SamNicholson (29 commits)")[![gsw945](https://avatars.githubusercontent.com/u/6281968?v=4)](https://github.com/gsw945 "gsw945 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/snicholson-slimfilecache/health.svg)

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

###  Alternatives

[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)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

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