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

ActiveLibrary[Caching](/categories/caching)

ophelios/php-apcu-cache
=======================

Simple APCu cache strategy compatible with PSR-16 for PHP.

1.0.0(10mo ago)1401MITPHPPHP &gt;=8.4CI passing

Since Sep 12Pushed 10mo agoCompare

[ Source](https://github.com/ophelios-studio/php-apcu-cache)[ Packagist](https://packagist.org/packages/ophelios/php-apcu-cache)[ RSS](/packages/ophelios-php-apcu-cache/feed)WikiDiscussions main Synced 3w ago

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

PHP APCu Cache (PSR-16)
=======================

[](#php-apcu-cache-psr-16)

[![Maintainability](https://camo.githubusercontent.com/e877232269ad76df98c0b0cf0a724672ee741321ed58b8a179d7ca16ebf35a2a/68747470733a2f2f716c74792e73682f6261646765732f66316133663038622d663430322d343537382d383535392d6561313138313631383139322f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/ophelios-studio/projects/php-apcu-cache)[![Code Coverage](https://camo.githubusercontent.com/09c56d32a7e6ff9e43f8207f0855226d80d521b88cdb0a886293454ebb136b51/68747470733a2f2f716c74792e73682f6261646765732f66316133663038622d663430322d343537382d383535392d6561313138313631383139322f636f7665726167652e737667)](https://qlty.sh/gh/ophelios-studio/projects/php-apcu-cache)

A tiny, dependency-free APCu cache implementation compatible with PSR-16 (Simple Cache) for PHP. It provides a thin wrapper around APCu functions with sensible key validation and TTL handling.

Features
--------

[](#features)

- PSR-16 compliant interface (get/set/delete/has and multi-operations)
- APCu-backed, in-memory, super fast
- TTL support via integers or DateInterval
- Strict key validation per PSR-16 (forbidden characters: `{ } ( ) / \ @ :` and empty keys)
- Utility to list current APCu cache entries (ApcuCache::getList)

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

[](#requirements)

- PHP 8.4+
- APCu extension enabled at runtime

Note: The test suite ships with a lightweight APCu polyfill so tests can run without the APCu extension. In production, you must have APCu installed and enabled.

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

[](#installation)

Install with Composer:

```
composer require ophelios/php-apcu-cache

```

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

[](#quick-start)

```
use Cache\ApcuCache;

$cache = new ApcuCache();

// Set and get
$cache->set('greeting', 'hello world');
echo $cache->get('greeting'); // hello world

// Default value if missing
echo $cache->get('missing', 'default'); // default

// TTL as seconds
$cache->set('token', 'abc', 300); // 5 minutes

// TTL as DateInterval
$cache->set('short', 'value', new DateInterval('PT30S'));

// Existence
if ($cache->has('token')) {
    // ...
}

// Delete and clear
$cache->delete('token');
$cache->clear();
```

### Multi operations

[](#multi-operations)

```
use Cache\ApcuCache;

$cache = new ApcuCache();
$cache->setMultiple([
    'a' => 1,
    'b' => 2,
]);

$values = $cache->getMultiple(['a', 'b', 'c'], 'x');
// ['a' => 1, 'b' => 2, 'c' => 'x']

$cache->deleteMultiple(['a', 'b']);
```

API notes
---------

[](#api-notes)

- Key validation: Empty keys or keys containing any of `{ } ( ) / \\ @ :` will throw `Cache\\Exceptions\\InvalidArgumentException`.
- TTL conversion:
    - `null` means no expiration (APCu 0)
    - `0` is treated as expired (`-1` internally)
    - Values &gt; 30 days are converted to absolute timestamps
- Availability: You can check if APCu is enabled using `ApcuCache::isAvailable()`.
- Listing cache: `ApcuCache::getList()` returns APCu cache entries (best-effort; structure depends on APCu).

Testing
-------

[](#testing)

This project uses PHPUnit 10.

Run tests:

```
vendor/bin/phpunit

```

Code coverage requires Xdebug or PCOV. If available, you can run:

```
XDEBUG_MODE=coverage vendor/bin/phpunit

```

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

[](#contributing)

Contributions are welcome!

- Open an issue for bugs or feature requests.
- Submit a PR with a clear description and tests.

Dev setup:

- Install dependencies: `composer install`
- Run tests: `vendor/bin/phpunit`

License
-------

[](#license)

MIT License © 2025 Ophelios. See LICENSE for details.

###  Health Score

34

—

LowBetter than 74% of packages

Maintenance53

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

329d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/118052280?v=4)[ophelios](/maintainers/ophelios)[@Ophelios](https://github.com/Ophelios)

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.9k556.2M21.1k](/packages/laravel-framework)[illuminate/contracts

The Illuminate Contracts package.

707133.3M14.8k](/packages/illuminate-contracts)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.8M173](/packages/algolia-algoliasearch-client-php)[moonshine/moonshine

Laravel administration panel

1.3k268.2k87](/packages/moonshine-moonshine)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

86337.5k](/packages/flow-php-flow)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

758297.9k49](/packages/civicrm-civicrm-core)

PHPackages © 2026

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