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

Abandoned → [symfony/cache](/?search=symfony%2Fcache)ArchivedLibrary[Caching](/categories/caching)

odan/cache
==========

PHP OpCache implementation of PSR-16 Simple Cache Interface

0.5.0(5y ago)113.8k11MITPHPPHP ^7.2 || ^8

Since Feb 1Pushed 5y ago3 watchersCompare

[ Source](https://github.com/odan/cache)[ Packagist](https://packagist.org/packages/odan/cache)[ Docs](https://github.com/odan/cache)[ RSS](/packages/odan-cache/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (8)Dependencies (6)Versions (9)Used By (1)

OpCache Adapter (PSR-16 )
=========================

[](#opcache-adapter-psr-16-)

A PSR-16 Simple Cache Implementation.

[![Latest Version on Packagist](https://camo.githubusercontent.com/af71e444054933e345431ae5247c27a2e2eace47e0503d099ac2dae243af901b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6f64616e2f63616368652e737667)](https://packagist.org/packages/odan/cache)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://github.com/odan/cache/workflows/build/badge.svg)](https://github.com/odan/cache/actions)[![Coverage Status](https://camo.githubusercontent.com/8b49e3f8346702d8ab62f66e4968aa7014f3dccab486c1297aba5ff9c604d2a1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6f64616e2f63616368652e737667)](https://scrutinizer-ci.com/g/odan/cache/code-structure)[![Quality Score](https://camo.githubusercontent.com/1ca2e48ed42ebdf170266b3f331c6374b673fe9487f357f5d51cfb7629cdebf9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6f64616e2f63616368652e737667)](https://scrutinizer-ci.com/g/odan/cache/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/4755f99d44a67b947a86af5bdd0487ec96432e64b8fc95c377935b04de04e168/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f64616e2f63616368652e737667)](https://packagist.org/packages/odan/cache/stats)

Out-of-the-Box Bytecode Cache
-----------------------------

[](#out-of-the-box-bytecode-cache)

PHP is an interpreted language. The default PHP runtime compiles PHP sourcecode to an intermediate representation called PHP bytecode which is then executed. A bytecode cache stores this compiled representation of PHP sourcecode in shared memory. This eliminates the need to load and compile sourcecode on each request which leads to a significant increase in performance (up to 70% more requests per second).

The basic idea, when executing a PHP script is in two steps:

- First: the PHP code, written in plain-text, is **compiled to opcodes**
- Then: those **opcodes are executed**.

When you have one PHP script, as long as it is not modified, the opcodes will always be the same ; so, doing the compilation phase each time that script is to be executed is kind of a waste of CPU-time.

To prevent that redundant-compilation, there are some opcode caching mechanism that you can use.

Once the PHP script has been compiled to opcodes, those will be kept in RAM -- and directly used from memory the next time the script is to be executed ; preventing the compilation from being done again and again.

**Read more**

-
-

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

[](#requirements)

- PHP 7.2+ or 8.0+

Installation
------------

[](#installation)

```
composer require odan/cache

```

Usage
-----

[](#usage)

```
$cachePath = sys_get_temp_dir() . '/cache';

$cache = new \Odan\Cache\Simple\OpCache($cachePath);

// set a opcache value
$cache->set('foo', 'bar');

// get a opcache value
echo $cache->get('foo'); // bar
```

Known issues
------------

[](#known-issues)

> Fatal error: Call to undefined method stdClass::\_\_set\_state()

If there are objects in the value, they will be written as `stdClass::__set_state()`. This is fine for objects where `__set_state()` can be added, but it can't be added to `stdClass`.

To fix this issue just serialize the value you are trying to cache:

```
$cache->set('key', serialize($object));
```

Then unserialize the string back to the original value:

```
$object = unserialize($cache->get('key'));
```

### Race conditions

[](#race-conditions)

If you're in a high-concurrency environment you should avoid using a filesystem cache. Multiple operations on the file system are very hard to make atomic in PHP.

Similar components
------------------

[](#similar-components)

- [laminas/laminas-cache](https://docs.laminas.dev/laminas-cache/psr16/) - See the Filesystem Adapter
- [Symonfy Php Files Cache Adapter](https://symfony.com/doc/current/components/cache/adapters/php_files_adapter.html)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.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.

###  Release Activity

Cadence

Every ~201 days

Recently: every ~348 days

Total

8

Last Release

1977d ago

PHP version history (3 changes)0.1.0PHP &gt;=5.5.9

0.2.0PHP &gt;=7.0

0.5.0PHP ^7.2 || ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/89d408d7f6ed65cdbeba70a2da2d0a8a1135fc37ebc07c44989f509221cc91bd?d=identicon)[odan](/maintainers/odan)

---

Top Contributors

[![odan](https://avatars.githubusercontent.com/u/781074?v=4)](https://github.com/odan "odan (44 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

phpcachecachingpsr-16Opcachepsr16

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[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)[graham-campbell/bounded-cache

A Bounded TTL PSR-16 Cache Implementation

101.9M6](/packages/graham-campbell-bounded-cache)[webarchitect609/bitrix-cache

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

2831.2k8](/packages/webarchitect609-bitrix-cache)[apix/simple-cache

The PSR-16 extension to Apix-Cache.

1017.4k](/packages/apix-simple-cache)

PHPackages © 2026

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