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

ActiveLibrary[Caching](/categories/caching)

voku/simple-cache
=================

Simple Cache library

6.1.0(1mo ago)322.6M↓40.3%12[1 issues](https://github.com/voku/simple-cache/issues)[2 PRs](https://github.com/voku/simple-cache/pulls)7MITPHPPHP &gt;=8.0.0CI passing

Since Jan 26Pushed 4w ago6 watchersCompare

[ Source](https://github.com/voku/simple-cache)[ Packagist](https://packagist.org/packages/voku/simple-cache)[ Docs](https://github.com/voku/simple-cache)[ Fund](https://www.paypal.me/moelleken)[ GitHub Sponsors](https://github.com/voku)[ RSS](/packages/voku-simple-cache/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (7)Versions (65)Used By (7)

[![CI](https://github.com/voku/simple-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/voku/simple-cache/actions/workflows/ci.yml)[![FOSSA Status](https://camo.githubusercontent.com/42b2cddbb1a908aa6ed734ae73ef19980f6546c8fa661581f4203afd84873c69/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246766f6b7525324673696d706c652d63616368652e7376673f747970653d736869656c64)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvoku%2Fsimple-cache?ref=badge_shield)[![Coverage Status](https://camo.githubusercontent.com/3a98f94c9927114170a6149092ef01b6e87fa8ce5c464334e83e26a418adb3ea/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f766f6b752f73696d706c652d63616368652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/voku/simple-cache?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4ac6b226c33018a1e86768e3185b4e943a9a7b93e28f9415720286dd2beac24f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f766f6b752f73696d706c652d63616368652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/voku/simple-cache/?branch=master)[![Codacy Badge](https://camo.githubusercontent.com/3aa49a5de71658ecc6cbc21be2bb24a4b2b5ff3eed13fe56def64b1372c5f9db/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3538343664326134363539393438363438366233393536633063653131613138)](https://www.codacy.com/app/voku/simple-cache)[![Latest Stable Version](https://camo.githubusercontent.com/d23cd75edf44e137f481d6f3bd40b0f08ba37f85c5e67fdb63cd2e02fbe3f6b0/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f73696d706c652d63616368652f762f737461626c65)](https://packagist.org/packages/voku/simple-cache)[![Total Downloads](https://camo.githubusercontent.com/d73c3a5bc23f102283c538a43293d64d0c2f2a9a417b6865d18dfee1d550459f/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f73696d706c652d63616368652f646f776e6c6f616473)](https://packagist.org/packages/voku/simple-cache)[![License](https://camo.githubusercontent.com/4262fc2881e7ad5b60c393cf355bc252aafce88fab81b204bb4c1ba32a1bc3ec/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f73696d706c652d63616368652f6c6963656e7365)](https://packagist.org/packages/voku/simple-cache)[![Donate to this project using Paypal](https://camo.githubusercontent.com/0d6e4d8b50b5983a58205941b1a581b1305903393b7a39da574e3f60af3c7f5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d79656c6c6f772e737667)](https://www.paypal.me/moelleken)[![Donate to this project using Patreon](https://camo.githubusercontent.com/f9e075baad95563481d35174d43ef50757281abb6bc795d0f473fad452afa030/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d79656c6c6f772e737667)](https://www.patreon.com/voku)

⚡ Simple Cache Class
====================

[](#zap-simple-cache-class)

This is a simple Cache Abstraction Layer for PHP &gt;= 8.0 that provides a simple interaction with your cache-server. You can define the Adapter / Serializer in the "constructor" or the class will auto-detect you server-cache in this order:

1. Memcached / Memcache
2. Redis
3. Xcache
4. APC / APCu
5. OpCache (via PHP-files)
6. Static-PHP-Cache

### Get "Simple Cache"

[](#get-simple-cache)

You can download it from here, or require it using [composer](https://packagist.org/packages/voku/simple-cache).

```
{
  "require": {
    "voku/simple-cache": "5.*"
  }
}
```

### Install via "composer require"

[](#install-via-composer-require)

```
composer require voku/simple-cache
```

### Quick Start

[](#quick-start)

```
use voku\cache\Cache;

require_once 'composer/autoload.php';

$cache = new Cache();
$ttl = 3600; // 60s * 60 = 1h
$cache->setItem('foo', 'bar', $ttl);
$bar = $cache->getItem('foo');
```

### Usage

[](#usage)

```
use voku\cache\Cache;

$cache = new Cache();

if ($cache->getCacheIsReady() === true && $cache->existsItem('foo')) {
  return $cache->getItem('foo');
} else {
  $bar = someSpecialFunctionsWithAReturnValue();
  $cache->setItem('foo', $bar);
  return $bar;
}
```

If you have an heavy task e.g. a really-big-loop, then you can also use static-cache. But keep in mind, that this will be stored into PHP (it needs more memory).

```
use voku\cache\Cache;

$cache = new Cache();

if ($cache->getCacheIsReady() === true && $cache->existsItem('foo')) {
  for ($i = 0; $i cache->getItem('foo', 3); // use also static-php-cache, when we hit the cache 3-times
  }
  return $cache->getItem('foo');
} else {
  $bar = someSpecialFunctionsWithAReturnValue();
  $cache->setItem('foo', $bar);
  return $bar;
}
```

PS: By default, the static cache is also used by &gt;= 10 cache hits. But you can configure this behavior via $cache-&gt;setStaticCacheHitCounter(INT).

No-Cache for the admin or a specific ip-address
-----------------------------------------------

[](#no-cache-for-the-admin-or-a-specific-ip-address)

If you use the parameter "$checkForUser" (=== true) in the constructor, then the cache isn't used for the admin-session.

-&gt; You can also overwrite the check for the user, if you add a global function named "checkForDev()".

Overwrite the auto-connection option
------------------------------------

[](#overwrite-the-auto-connection-option)

You can overwrite the cache auto-detect via "CacheAdapterAutoManager" and the "$cacheAdapterManagerForAutoConnect" option in the "Cache"-constructor. Additional you can also activate the "$cacheAdapterManagerForAutoConnectOverwrite" option in the "Cache"-constructor, so that you can implement your own cache auto-detect logic.

```
$cacheManager = new \voku\cache\CacheAdapterAutoManager();

// 1. check for "APCu" support first
$cacheManager->addAdapter(
    \voku\cache\AdapterApcu::class
);

// 2. check for "APC" support
$cacheManager->addAdapter(
    \voku\cache\AdapterApcu::class
);

// 3. try "OpCache"-Cache
$cacheManager->addAdapter(
    \voku\cache\AdapterOpCache::class,
    static function () {
        $cacheDir = \realpath(\sys_get_temp_dir()) . '/simple_php_cache_opcache';

        return $cacheDir;
    }
);

// 4. try "File"-Cache
$cacheManager->addAdapter(
    \voku\cache\AdapterFileSimple::class,
    static function () {
        $cacheDir = \realpath(\sys_get_temp_dir()) . '/simple_php_cache_file';

        return $cacheDir;
    }
);

// 5. use Memory Cache as final fallback
$cacheManager->addAdapter(
    \voku\cache\AdapterArray::class
);

$cache = new \voku\cache\CachePsr16(
    null, // use auto-detection
    null, // use auto-detection
    false, // do not check for usage
    true, // enable the cache
    false, // do not check for admin session
    false, // do not check for dev
    false, // do not check for admin session
    false, // do not check for server vs. client ip
    '', // do not use "_GET"-parameter for disabling
    $cacheManager, // new auto-detection logic
    true // overwrite the auto-detection logic
);
```

### Support

[](#support)

For support and donations please visit [Github](https://github.com/voku/simple-cache/) | [Issues](https://github.com/voku/simple-cache/issues) | [PayPal](https://paypal.me/moelleken) | [Patreon](https://www.patreon.com/voku).

For status updates and release announcements please visit [Releases](https://github.com/voku/simple-cache/releases) | [Twitter](https://twitter.com/suckup_de) | [Patreon](https://www.patreon.com/voku/posts).

For professional support please contact [me](https://about.me/voku).

### Thanks

[](#thanks)

- Thanks to [GitHub](https://github.com) (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
- Thanks to [IntelliJ](https://www.jetbrains.com) as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to [GitHub Actions](https://github.com/features/actions) for powering the project's continuous integration pipeline.
- Thanks to [StyleCI](https://styleci.io/) for the simple but powerfull code style check.
- Thanks to [PHPStan](https://github.com/phpstan/phpstan) &amp;&amp; [Psalm](https://github.com/vimeo/psalm) for relly great Static analysis tools and for discover bugs in the code!

### License

[](#license)

[![FOSSA Status](https://camo.githubusercontent.com/3b70f7ea82a30e61972f5801d10d81a807c1a2c331b62fa00ce1ffea2f4d8070/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246766f6b7525324673696d706c652d63616368652e7376673f747970653d6c61726765)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvoku%2Fsimple-cache?ref=badge_large)

###  Health Score

68

—

FairBetter than 99% of packages

Maintenance92

Actively maintained with recent releases

Popularity53

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 78.6% 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 ~79 days

Recently: every ~557 days

Total

53

Last Release

47d ago

Major Versions

1.1.2 → 2.02015-07-07

2.4.0 → 3.0.02017-11-25

3.2.2 → 4.0.02019-02-24

4.1.0 → 5.0.02025-10-29

5.0.0 → 6.0.02026-04-21

PHP version history (3 changes)1.0.0PHP &gt;=5.3.0

3.0.0PHP &gt;=7.0.0

6.0.0PHP &gt;=8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6456fe693db197c458272cb758bf78958bc7d3e787ccd59db4bf3cf41654316a?d=identicon)[voku](/maintainers/voku)

---

Top Contributors

[![voku](https://avatars.githubusercontent.com/u/264695?v=4)](https://github.com/voku "voku (136 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (22 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (5 commits)")[![Bilge](https://avatars.githubusercontent.com/u/470626?v=4)](https://github.com/Bilge "Bilge (2 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (2 commits)")[![fossabot](https://avatars.githubusercontent.com/u/29791463?v=4)](https://github.com/fossabot "fossabot (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (1 commits)")

---

Tags

cachecache-storagecaching-librarycaching-strategieshacktoberfestphpphpcachecachingsimple-cache

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k757.1M2.5k](/packages/psr-simple-cache)[mmamedov/page-cache

PageCache is a lightweight PHP library for full page cache. It uses various strategies to differentiate among separate versions of the same page.

7913.1k1](/packages/mmamedov-page-cache)[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2987.3k1](/packages/alekseykorzun-memcached-wrapper-php)

PHPackages © 2026

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