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

ActiveLibrary[Caching](/categories/caching)

lingualeo/php-cache
===================

LinguaLeo Caching Library

0.9.0(9y ago)212.2kMITPHPPHP &gt;=5.4.0

Since Nov 26Pushed 9y ago19 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (20)Used By (0)

php-cache
=========

[](#php-cache)

**PHP-Cache** is a library designed to simplify your work with the different cache storage engines. Currently library is under heavy development so API can change in the future.

Example using Redis:

```
$redis = new \Redis();
$redis->connect('127.0.0.1');
$cache = new RedisCache($redis);

$cache->set('test', 'data'); //write 'data' by key 'test'
$cache->get('test'); //returns 'data'
```

Also atomic CAS-like operations supported (**create** and **update**). For example:

```
$modifier = function (&$data) {
    $data = 'value';
};
$result = $this->cache->create('test', $modifier);
```

**Data** represents the reference to information that storage already contains. You can modify or completly replace it inside the callable.

If other client will change **Data** before you call **create** you will get an **AtomicViolationException**. In your client code you can catch this exception and retry operation.

The main difference betweeen **create** and **update** methods is that **update** will do nothing in case storage doesn't contains the specified key.

### Decorators

[](#decorators)

Currently library provides only one additional **HotCacheDecorator** which is very useful in a highloaded environment: it simply stores (and modifies) all cached data in a in-memory array. So if you call **get** once then all subsequent calls will be served only by hot cache without any requests to storage server.

To enable hot cache just wrap your creation of any **CacheProvider** object with the decorator:

```
$redis = new \Redis();
$redis->connect('127.0.0.1');
$cache = new HotCacheDecorator(new RedisCache($redis));
```

### Cache key generation

[](#cache-key-generation)

Library provides simple mechanism to generate cache keys with **generateCacheKey** method of **CacheProvider**:

```
$key = CacheProvider::generateCacheKey('arg1', 'arg2'); //cache:arg1:arg2
```

You can pass any number of arguments (&gt; 0) to this method in order to get a fresh shiny cache key. Also as the first parameter you can pass some class name and if this class will contain constant field **VERSION** then it's value will be mixed up with other arguments of **generateCacheKey**:

```
class Test {
    const VERSION = 2;
}
...
$key = CacheProvider::generateCacheKey('Test', 'arg1', 'arg2'); //cache:Test:arg1:arg2:2
```

This behavior is very useful when you work with ORM models and want to cache different versions of objects without need to drop all cache data after making some changes in a small single model.

### Testing

[](#testing)

Setup [Vagrant](https://www.vagrantup.com/downloads.html) and [Virtualbox](https://www.virtualbox.org/wiki/Downloads).

```
vagrant up
phpunit
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.9% 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 ~77 days

Recently: every ~215 days

Total

17

Last Release

3310d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/254cf1d4fe35b98488bb7769f8873dcf93b8aa9d5462e9e41343f2a1285f3275?d=identicon)[LinguaLeo](/maintainers/LinguaLeo)

---

Top Contributors

[![justgoodman](https://avatars.githubusercontent.com/u/8512397?v=4)](https://github.com/justgoodman "justgoodman (34 commits)")[![alexandrfox](https://avatars.githubusercontent.com/u/199416?v=4)](https://github.com/alexandrfox "alexandrfox (8 commits)")[![rdmrcv](https://avatars.githubusercontent.com/u/242112?v=4)](https://github.com/rdmrcv "rdmrcv (2 commits)")[![drscre](https://avatars.githubusercontent.com/u/844519?v=4)](https://github.com/drscre "drscre (1 commits)")[![vtk13](https://avatars.githubusercontent.com/u/1214834?v=4)](https://github.com/vtk13 "vtk13 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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