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(9y ago)117.0k5[2 issues](https://github.com/SamNicholson/slimfilecache/issues)apache 2.0PHP

Since Oct 4Pushed 9y ago3 watchersCompare

[ Source](https://github.com/SamNicholson/slimfilecache)[ Packagist](https://packagist.org/packages/snicholson/slimfilecache)[ RSS](/packages/snicholson-slimfilecache/feed)WikiDiscussions master Synced 3d 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 75% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity27

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

3329d 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

[oat-sa/tao-core

TAO core extension

66143.7k124](/packages/oat-sa-tao-core)[phlak/directory-lister

PHP directory lister

2.5k1.4k](/packages/phlak-directory-lister)[bacula-web/bacula-web

The open source web based reporting and monitoring tool for Bacula

1557.7k](/packages/bacula-web-bacula-web)[brandembassy/slim-nette-extension

19201.2k](/packages/brandembassy-slim-nette-extension)[egroupware/openid

EGroupware OpenID Connect / OAuth2 server

1228.1k4](/packages/egroupware-openid)[abouvier/slim-redis-cache

Redis cache middleware for Slim framework

172.0k](/packages/abouvier-slim-redis-cache)

PHPackages © 2026

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