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

ActiveLibrary[Caching](/categories/caching)

emilio/php-cache
================

Minimal caching library

9156PHP

Since Jan 4Pushed 9y ago2 watchersCompare

[ Source](https://github.com/emilio/php-cache)[ Packagist](https://packagist.org/packages/emilio/php-cache)[ RSS](/packages/emilio-php-cache/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (2)Used By (0)

PHP filesystem backed cache
===========================

[](#php-filesystem-backed-cache)

This class provides an easy fs-backed cache.

[Read more (es)](http://emiliocobos.net/php-cache/) | [Contributors](https://github.com/ecoal95/php-cache/graphs/contributors)

Starting
--------

[](#starting)

You can see an easy example in the `examples/` dir.

You can also install this package with `composer`.

Configuration
-------------

[](#configuration)

There are two main options: `cache_path` y `expires`.

- `cache_path` is the directory where cache will be stored. It's a relative directory by default (`cache`), but it's recommendable to re-configure it.
- `expires` is the cache expiration time **in minutes**.

**Important**: `cache_path` should be writable (that's obvious), but if it's public in the server, which is not recommended, you should forbid access to it.

A way to do it for Apache is having a `.htaccess` as follows in the cache dir:

```
deny from all

```

Usage
-----

[](#usage)

To store any data type you should use the `put` method using an identifier, and the value.

```
Cache::put('key', 'value');
```

### Retrieving data

[](#retrieving-data)

To get data stored in the cache you should use:

```
Cache::get('key');
```

If the item is not found, or it's expired, it will return `null`.

#### Raw data

[](#raw-data)

You can store and retrieve raw data, to prevent decoding and encoding overhead.

You should specify it's raw data in both `put()` and `get()`, as follows:

```
Cache::put($key, $big_chunk_of_data, true);
// ...
Cache::get($key, true);
```

### Deleting data

[](#deleting-data)

You may delete a single item from de cache using the `delete()` method:

```
Cache::delete($key);
```

You may also flush all the cache to delete everything:

```
Cache::flush();
```

Race conditions
---------------

[](#race-conditions)

This library makes atomic writes via `rename`, so no race condition should be possible.

Performance
-----------

[](#performance)

There are some benchmarks over the `benchmarks/` directory.

They're simple ones and you're encouraged to write more extensive ones. In general, **the performance difference compared with memcached or apc is almost unnoticeable with large chunks of data, but it's relatively high with small data fragments**. That's expected due to the fs access overhead.

There are also legacy tests by a contributor in the `legacy-tests` folder which test performance and race-condition ressistance.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% 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/4107d42878755124aba7539042ce67899caf85b4e47b35f0fd5c39bba8a28fad?d=identicon)[ecoal95](/maintainers/ecoal95)

---

Top Contributors

[![emilio](https://avatars.githubusercontent.com/u/1323194?v=4)](https://github.com/emilio "emilio (21 commits)")[![logicaalternativa](https://avatars.githubusercontent.com/u/4106207?v=4)](https://github.com/logicaalternativa "logicaalternativa (5 commits)")[![Sloy](https://avatars.githubusercontent.com/u/545251?v=4)](https://github.com/Sloy "Sloy (1 commits)")

### Embed Badge

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

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

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)

PHPackages © 2026

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