PHPackages                             ppajer/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. ppajer/cache

ActiveLibrary[Caching](/categories/caching)

ppajer/cache
============

A simple filesystem based cache in PHP. Ideal for caching large API responses that rarely need updating.

00PHP

Since May 31Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ppajer/Cache)[ Packagist](https://packagist.org/packages/ppajer/cache)[ RSS](/packages/ppajer-cache/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Cache
=====

[](#cache)

A simple filesystem based cache in PHP. Ideal for caching large API responses that rarely need updating.

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

[](#installation)

Install as a Composer package or download this repository and include the class in your project.

Usage
-----

[](#usage)

To have your data automatically cached, create a new Cache instance by specifying a file path and an expiry time in seconds. If the file doesn't exist, it will be created.

```

$path = 'cache.json';
$expiry = 36000;
$cache = new Cache($path, $expiry);

if ($cache->needsUpdate()) {
  $data = // get some new data;
  $cache->write($data);
 } else {
  $data = $cache->read();
 }

```

Declarative updates
-------------------

[](#declarative-updates)

The above method lets you control when and if your cache is updated, but if you don't require that level of control you can simply pass a function that returns the updated data for the cache in case it is expired, and let it handle the rest. This is useful if your data is not likely to change dynamically and you just need up-to-date caches to read from.

```

function get_data() {
 // do something here
 return $data;
}

class API {
 public static function get_data() {
   // some api stuff
   return $data;
  }
}

$cache = new Cache('cache.json', 36000, 'get_data'); // Cache will update itself using the provided function if expired
$apiCache = new Cache('api.json', 36000, array(API::class, 'get_data')); // Accepts any callable that returns data

```

Interface
---------

[](#interface)

```
interface ICache {
   public function write($data) : bool;
   public function read() : string;
   public function needsUpdate() : bool;
}

```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e6212007de7bf9a8e3591e60269ffaf607a962926182e21646b8f9975a879e4?d=identicon)[ppajer](/maintainers/ppajer)

---

Top Contributors

[![ppajer](https://avatars.githubusercontent.com/u/5861559?v=4)](https://github.com/ppajer "ppajer (10 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/ppajer-cache/health.svg)](https://phpackages.com/packages/ppajer-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)
