PHPackages                             juanchosl/simplecache - 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. juanchosl/simplecache

ActiveLibrary[Caching](/categories/caching)

juanchosl/simplecache
=====================

A small collection of read/write for multiples cache systems using PSR-16

1.0.6(6mo ago)1146↓100%MITPHPPHP ^7.2 || ^8.0

Since Sep 27Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/JuanchoSL/SimpleCache)[ Packagist](https://packagist.org/packages/juanchosl/simplecache)[ Docs](https://github.com/JuanchoSL/SimpleCache)[ RSS](/packages/juanchosl-simplecache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (8)Versions (10)Used By (0)

SimpleCache
===========

[](#simplecache)

Description
-----------

[](#description)

A small collection of read/write functions for multiples cache systems

Install
-------

[](#install)

```
composer require juanchosl/simplecache
```

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

[](#performance)

From faster to slower

- Process: It's only valid for current request execution
- Session: Only valid for a current user session
- Memcached: If Memcached service is available and Memcached library is installed
- Redis: If Redis service is available and Redis library is installed
- Memcache: If Memcached service is available and Memcache library is installed
- File: The most compatible system, file into filesystem, but slower

How use it
----------

[](#how-use-it)

### Use directly one of the available libs

[](#use-directly-one-of-the-available-libs)

#### For create a cache instance

[](#for-create-a-cache-instance)

```
use JuanchoSL\SimpleCache\Repositories\ProcessCache;

$cache = new ProcessCache($_ENV['CACHE_ENVIRONMENT']);
//The max time to expire is 30 days if you do not set a time
$cache->setMaxTtl(3600 * 24);
```

#### For write a cache index

[](#for-write-a-cache-index)

Set into `$cache_key` the `$value`, valid for `$ttl` seconds or default TTL if you don not pass a value

```
$result = $cache->set(string $cache_key, mixed $value, int $ttl = 0);
```

#### For read a cache index

[](#for-read-a-cache-index)

Read from cache the contents of `$cache_key` and return his value or `$default` if it not exists or it is not valid

```
$cache_value = $cache->get(string $cache_key, $default = null);
```

#### For delete a cache index

[](#for-delete-a-cache-index)

Delete from cache the value with `$cache_key`

```
$result = $cache->delete(string $cache_key);
```

#### For write multiple cache indexes

[](#for-write-multiple-cache-indexes)

Set into `$cache_key` the `$values`, an iterable containing a list of `$cache_key => $value` pairs, valid for `$ttl` seconds or default TTL if you don not pass a value

```
$result = $cache->setMultiple(iterable $values, \DateInterval|int $ttl = 0);
```

#### For read multiple cache indexes

[](#for-read-multiple-cache-indexes)

Read from cache the contents of `$cache_keys` and return a list of `$key => $value` pairs. Missed keys has the `$default` value

```
$cache_value = $cache->getMultiple(iterable $cache_keys, $default = null);
```

#### For delete a cache index

[](#for-delete-a-cache-index-1)

Delete from cache the values from the `$cache_keys` list

```
$result = $cache->deleteMultiple(iterable $cache_keys);
```

#### For replace a cache index

[](#for-replace-a-cache-index)

Replace into cache the value with `$cache_key` with the `$new_value` without change his expiration time

```
$result = $cache->replace(string $cache_key, mixed $new_value);
```

#### For change the time to live of cache index

[](#for-change-the-time-to-live-of-cache-index)

Change the expiration time of `$cache_key` with the new one passed as `$new_ttl`

```
$result = $cache->touch(string $cache_key, \DateInterval|int $new_ttl);
```

#### For increment a cache index numeric value

[](#for-increment-a-cache-index-numeric-value)

Increments the value into `$cache_key` adding `$numeric_increment` to his value. If not exists it is created.

```
$result = $cache->increment(string $cache_key, int|float $numeric_increment, \DateInterval|int $ttl_if_not_exists = $max_ttl);
```

#### For decrement a cache index numeric value

[](#for-decrement-a-cache-index-numeric-value)

Decrements the value into `$cache_key` subtracting `$numeric_decrement` to his value. If not exists it is created.

```
$result = $cache->decrement(string $cache_key, int|float $numeric_decrement, \DateInterval|int $ttl_if_not_exists = $max_ttl);
```

#### For check if the cache contains a `$cache_key`

[](#for-check-if-the-cache-contains-a-cache_key)

Check if key exists, is not recommended, because can be return true and just another script can remove it

```
$result = $cache->has(string $cache_key);
```

#### For clear all cache indexes

[](#for-clear-all-cache-indexes)

Remove all data from cache

```
$result = $cache->clear();
```

### Use the provided adapter for use with compatibility with PSR-16 Simple-Cache

[](#use-the-provided-adapter-for-use-with-compatibility-with-psr-16-simple-cache)

#### Create a cache instance

[](#create-a-cache-instance)

After create a Cache Instance, you can use it with the provided PsrSimpleCacheAdapter in order to work conform the PSR-16

```
use JuanchoSL\SimpleCache\Repositories\ProcessCache;
use JuanchoSL\SimpleCache\Adapters\PsrSimpleCacheAdapter;

$lib = new ProcessCache($_ENV['CACHE_ENVIRONMENT']);
$cache = new PsrSimpleCacheAdapter($lib);
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance73

Regular maintenance activity

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~128 days

Recently: every ~153 days

Total

7

Last Release

192d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd6d3dea7eb469817524c42a80683e95793ed4800a6794366503355af046a726?d=identicon)[Juanchosl](/maintainers/Juanchosl)

---

Top Contributors

[![JuanchoSL](https://avatars.githubusercontent.com/u/18701207?v=4)](https://github.com/JuanchoSL "JuanchoSL (50 commits)")

---

Tags

cachesimple-cachepsr-16redis-cachefile cachesession-cachememcached cachememcache cacheprocess cache

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juanchosl-simplecache/health.svg)

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

###  Alternatives

[laminas/laminas-cache

Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

1076.9M130](/packages/laminas-laminas-cache)[sabre/cache

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)[webarchitect609/bitrix-cache

Comfortable fluent interface for Bitrix cache. Anti-stampede cache protection.

2831.2k8](/packages/webarchitect609-bitrix-cache)

PHPackages © 2026

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