PHPackages                             benjamindean/one-line-apc - 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. benjamindean/one-line-apc

ActiveLibrary[Caching](/categories/caching)

benjamindean/one-line-apc
=========================

Dead simple wrapper class for APC and APCu which capable of setting and getting cached data in one line.

v0.1.1(10y ago)020MITPHPPHP &gt;=5.3.0

Since Apr 7Pushed 10y ago1 watchersCompare

[ Source](https://github.com/benjamindean/one-line-apc)[ Packagist](https://packagist.org/packages/benjamindean/one-line-apc)[ Docs](https://github.com/benjamindean/one-line-apc)[ RSS](/packages/benjamindean-one-line-apc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

OneLineAPC
==========

[](#onelineapc)

Dead simple wrapper class for [APC](http://php.net/manual/en/intro.apc.php) and [APCu](http://php.net/manual/en/intro.apcu.php) which capable of setting and getting cached data from a callback or a variable in one single line.

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

[](#requirements)

- PHP 5.3 or later
- `php-apc` extension installed

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

[](#installation)

Install with [Composer](https://getcomposer.org):

```
$ composer require benjamindean/one-line-apc

```

Usage
-----

[](#usage)

```
require 'vendor/autoload.php';
$cache = new OneLineAPC();
```

By default, this class uses [APC](http://php.net/manual/en/intro.apc.php). To use [APCu](http://php.net/manual/en/intro.apcu.php) just pass it while instantiating the class:

```
$cache = new OneLineAPC('apcu');
```

Default TTL is 79200 (22 hours). To change it, call `setTtl` method:

```
$cache->setTtl(3600);
```

OR, specify it individually as a last argument to `setCache` or `cached` methods:

```
$cache->setCache($dataToCache, 'key', 3600);
```

Cached
------

[](#cached)

The main and the most important method (the reason I created this class) is called `cached`:

```
$cache->cached('key', 'functionName');
```

`functionName` is the name of some function in your code which returns the data that needs to be cached. Any variable, integer or string will work too. You can also pass function arguments as a third argument here.

In case your function is within some class, pass it as an array of Object and a function name:

```
$cache->cached('key', array($obj, 'functionName'));
```

You can find out more about callbacks [here](http://php.net/manual/en/language.types.callable.php).

Examples
--------

[](#examples)

### Class method

[](#class-method)

```
class ReturnData {
    public function fetchData($url) {
        return file_get_contents($url);
    }
}

$obj = new ReturnData();

$apc = new OneLineAPC();
$apc->setTtl(3600);

return $apc->cached('key', array($obj, 'fetchData'), array('http://example.com/'));
```

### Function

[](#function)

```
function fetchData($url) {
    return file_get_contents($url);
}

$apc = new OneLineAPC();
$apc->setTtl(3600);

return $apc->cached('key', 'fetchData', array('http://example.com/'));
```

### Variable

[](#variable)

```
$something = 'Data to be cached';

$apc = new OneLineAPC();

return $apc->cached('key', $something, false, 3600);
```

Notes
-----

[](#notes)

If `apc` or `apcu` is not loaded, this class will generate "Notice", instead of "Fatal Error".

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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 ~1 days

Total

3

Last Release

3683d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b4bc79266837653c3cc8625f0ae099daa8ad8b3fe4b5aca5e699a512a43297b?d=identicon)[benjamindean](/maintainers/benjamindean)

---

Top Contributors

[![benjamindean](https://avatars.githubusercontent.com/u/5139993?v=4)](https://github.com/benjamindean "benjamindean (8 commits)")

---

Tags

cacheapcuapc

### Embed Badge

![Health badge](/badges/benjamindean-one-line-apc/health.svg)

```
[![Health](https://phpackages.com/badges/benjamindean-one-line-apc/health.svg)](https://phpackages.com/packages/benjamindean-one-line-apc)
```

###  Alternatives

[gordalina/cachetool

Manage your OPcache &amp; APCu cache through the CLI

1.8k3.7M5](/packages/gordalina-cachetool)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[sabre/cache

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

841.4M16](/packages/tedivm-stash-bundle)[cache/apcu-adapter

A PSR-6 cache implementation using apcu. This implementation supports tags

173.0M22](/packages/cache-apcu-adapter)[robinn/phpcacheadmin

A web dashboard for your favorite caching system.

4441.1k1](/packages/robinn-phpcacheadmin)

PHPackages © 2026

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