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

ActiveLibrary[Caching](/categories/caching)

initphp/cache
=============

A lightweight PSR-16 (Simple Cache) implementation with file, PDO, Redis, Memcache(d) and WinCache handlers.

1.0.0(3w ago)21051MITPHPPHP &gt;=8.0CI passing

Since Mar 17Pushed 3w ago1 watchersCompare

[ Source](https://github.com/InitPHP/Cache)[ Packagist](https://packagist.org/packages/initphp/cache)[ RSS](/packages/initphp-cache/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (5)Versions (3)Used By (1)

InitPHP Cache
=============

[](#initphp-cache)

A lightweight [PSR-16 (Simple Cache)](https://www.php-fig.org/psr/psr-16/)implementation with interchangeable handlers for the filesystem, PDO databases, Redis, Memcache(d) and WinCache.

[![CI](https://github.com/InitPHP/Cache/actions/workflows/ci.yml/badge.svg)](https://github.com/InitPHP/Cache/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/8200496604126a9df21d4c86cfd89608fe2d3f162fa4629f31e9b1e5465af32c/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f63616368652f76)](https://packagist.org/packages/initphp/cache) [![Total Downloads](https://camo.githubusercontent.com/d096c45c535c6361c357389522fb2c583810c9fbebf6dee878da16e65a1975a9/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f63616368652f646f776e6c6f616473)](https://packagist.org/packages/initphp/cache) [![License](https://camo.githubusercontent.com/170a9fc28ba049d125f182195f0fc81f3ee50f5a9984ebc40f0218d908613430/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f63616368652f6c6963656e7365)](https://packagist.org/packages/initphp/cache) [![PHP Version Require](https://camo.githubusercontent.com/e7c2497129c9dc9c95da765be7a68591766310e9cfa27897e009cfae955cf1b4/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f63616368652f726571756972652f706870)](https://packagist.org/packages/initphp/cache)

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- [`psr/simple-cache`](https://packagist.org/packages/psr/simple-cache) `^3.0`

Each handler may need its own PHP extension:

HandlerClassBackendNeedsFile`InitPHP\Cache\Handler\File`Filesystem— (core only)PDO`InitPHP\Cache\Handler\PDO`SQL database (MySQL, SQLite, PostgreSQL…)`ext-pdo`Redis`InitPHP\Cache\Handler\Redis`Redis`ext-redis` (phpredis)Memcache`InitPHP\Cache\Handler\Memcache`Memcached`ext-memcached` or `ext-memcache`WinCache`InitPHP\Cache\Handler\Wincache`WinCache user cache`ext-wincache` — *deprecated*Installation
------------

[](#installation)

```
composer require initphp/cache
```

Quick start
-----------

[](#quick-start)

```
require 'vendor/autoload.php';

use InitPHP\Cache\Cache;
use InitPHP\Cache\Handler\File;

$cache = Cache::create(File::class, [
    'path' => __DIR__ . '/var/cache',
]);

// Read-through pattern: compute and store on a miss.
$posts = $cache->get('posts');
if ($posts === null) {
    $posts = [
        ['id' => 12, 'title' => 'Post 12'],
        ['id' => 15, 'title' => 'Post 15'],
    ];
    $cache->set('posts', $posts, 120); // cache for 120 seconds
}

print_r($posts);
```

`Cache::create()` returns a handler that implements `InitPHP\Cache\CacheInterface`, which extends `Psr\SimpleCache\CacheInterface`. You can equally type-hint and pass any PSR-16 cache around your application.

Switching handlers
------------------

[](#switching-handlers)

Only the factory call changes; the cache API is identical for every backend.

```
use InitPHP\Cache\Cache;
use InitPHP\Cache\Handler\Redis;

$cache = Cache::create(Redis::class, [
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'database' => 0,
]);

$cache->set('user:42', ['name' => 'Jane'], 3600);
$cache->get('user:42');
```

API at a glance
---------------

[](#api-at-a-glance)

CallReturnsPurpose`get(string $key, mixed $default = null)``mixed`Read a value, or `$default` on a miss.`set(string $key, mixed $value, null|int|DateInterval $ttl = null)``bool`Store a value, optionally with a TTL.`delete(string $key)``bool`Remove one item.`clear()``bool`Remove every item this handler owns.`has(string $key)``bool`Whether a live item exists.`getMultiple(iterable $keys, mixed $default = null)``iterable`Read many items at once.`setMultiple(iterable $values, null|int|DateInterval $ttl = null)``bool`Store many items at once.`deleteMultiple(iterable $keys)``bool`Remove many items at once.`increment(string $key, int $offset = 1)``int`Add to a counter and return the new value.`decrement(string $key, int $offset = 1)``int`Subtract from a counter and return the new value.See [`docs/`](docs/README.md) for the full guide, including per-handler configuration and the exact semantics of TTLs, keys and counters.

Notes
-----

[](#notes)

- **TTL:** `null` means "store with no expiry"; a positive integer or `DateInterval` sets a lifetime; a zero or negative TTL deletes the item.
- **Keys:** any non-empty string that does not contain the PSR-16 reserved characters `{}()/\@:`. An invalid key throws an [`InvalidArgumentException`](docs/exceptions.md).
- **Counters:** `increment()`/`decrement()` treat a missing or non-numeric item as `0` and store the result without an expiry. They behave identically across every handler.
- **Values:** anything `serialize()` can handle round-trips exactly — including `null`, `false` and objects.

Documentation
-------------

[](#documentation)

- [Getting started](docs/getting-started.md)
- [Configuration &amp; options](docs/configuration.md)
- [PSR-16 behaviour &amp; the handler API](docs/psr-16.md)
- Handlers: [File](docs/file-handler.md) · [PDO](docs/pdo-handler.md) · [Redis](docs/redis-handler.md) · [Memcache(d)](docs/memcache-handler.md) · [WinCache](docs/wincache-handler.md)
- [Exceptions](docs/exceptions.md)

Contributing
------------

[](#contributing)

Bug reports and pull requests are welcome. CI runs PHP-CS-Fixer, PHPStan (max level) and PHPUnit across PHP 8.0–8.4, plus a Redis/Memcached integration job. Run the same static bundle locally with:

```
composer ci
```

See the [changelog](CHANGELOG.md) for release history.

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) &lt;&gt;

License
-------

[](#license)

Copyright © 2022 InitPHP — released under the [MIT License](./LICENSE).

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance63

Regular maintenance activity

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity34

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.

###  Release Activity

Cadence

Every ~1545 days

Total

2

Last Release

22d ago

Major Versions

0.1 → 1.0.02026-06-10

PHP version history (2 changes)0.1PHP &gt;=5.6

1.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (2 commits)")

---

Tags

cachecachingfile-cacheinitphpmemcachememcachedpdopdo-cachephpphp8psr-16redisredis-cachesimple-cachewincachephppdorediscachecachingsimple-cachepsr-16memcachedfile cacheinitphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sabre/cache

Simple cache abstraction layer implementing PSR-16

551.3M5](/packages/sabre-cache)[voku/simple-cache

Simple Cache library

332.7M10](/packages/voku-simple-cache)

PHPackages © 2026

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