PHPackages                             sci/cacheable - 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. sci/cacheable

ActiveLibrary[Caching](/categories/caching)

sci/cacheable
=============

Transparent caching library

1.0.1(10y ago)01[1 PRs](https://github.com/DrSchimke/cacheable/pulls)MITPHPPHP &gt;=5.4.0

Since Feb 21Pushed 8y ago1 watchersCompare

[ Source](https://github.com/DrSchimke/cacheable)[ Packagist](https://packagist.org/packages/sci/cacheable)[ RSS](/packages/sci-cacheable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (4)Used By (0)

Cacheable – A transparent caching library
=========================================

[](#cacheable--a-transparent-caching-library)

[![Build Status](https://camo.githubusercontent.com/78d384ded163c4b07246458dcbd6ae0bf55794e8ef3431b3dd9465967083e8d8/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f4472536368696d6b652f636163686561626c652e706e67)](http://travis-ci.org/DrSchimke/cacheable)[![Build Status](https://camo.githubusercontent.com/698ab10a48f98229104ffd549b0dec35c73ef0100cca7f84f76f698b2b757df0/68747470733a2f2f7374796c6563692e696f2f7265706f732f33393732393739372f736869656c64)](https://styleci.io/repos/39729797)

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

[](#installation)

Using [composer](https://getcomposer.org/download/):

```
composer require sci/cacheable

```

Usage
-----

[](#usage)

Lets say, you have a class `Foo`, implementing a method `Foo::bar()` with quite high time/resource consumption:

```
class Foo
{
    public function bar($a, $b)
    {
        // make some hard things with $a and $b
        ...

        return ...; // some result
    }
}

$foo = new Foo();

$bar = $foo->bar(1, 2); // takes some amount of time

// and later, again...
$bar = $foo->bar(1, 2); // takes the same amount of time, again
```

If there are no side-effects, the result of `Foo::bar()` is determined only by its arguments `$a` and `$b`. So you could use some cache, if eventuelly the method is called again. To avoid messing around with cache keys, you can use `sci\cacheable`:

```
use Sci\Cacheable;
use Sci\CacheTrait;

class Foo implements Cacheable
{
    use CacheTrait;

    public function bar($a, $b)
    {
        // make some hard things with $a and $b
        ...

        return ...; // some result
    }
}

$foo = new Foo();
$foo->setCache(/* any PSR-6 cache pool interface */)

$bar = $foo->cache()->bar(1, 2); // 1st call takes some time, but now, the result is stored into cache

// and later, again...
$bar = $foo->cache()->bar(1, 2); // 2nd call's result comes directly from cache
```

### en détail

[](#en-détail)

- A class to be cached (`Foo` in example above) implements the interface [`Sci\Cacheable`](lib/Cacheable.php) (which demands a method `cache()`).
- This can be done using [`Sci\CacheTrait`](lib/CacheTrait.php) (which additially provides a method `setCache()`).
- The method `setCache` gets as first argument a service, implementing [`Psr\Cache\CacheItemPoolInterface`](https://github.com/php-fig/cache/blob/master/src/CacheItemPoolInterface.php).
    - This cache pool is the actual cache backend.
    - An optional second argument to `setCache` is the default TTL (*time to live*) for all cached values.
- To use the cache, method calls are *proxied* through the method `cache()`, e.g. instead of `$foo->bar(1, 2)`, now we use `$foo->cache()->bar(1, 2)`.
    - Method `cache()` returns `$this`, i.e. it acts in a transparent way (fluent interface).
    - An optional argument for `cache()` allows to specify a TTL, different from the default one.

Implementation
--------------

[](#implementation)

License
-------

[](#license)

All contents of this package are licensed under the [MIT license](LICENSE).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

2

Last Release

3739d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5d3765b40a043c8c7c8ead0ae3cb9691ab6c053d272ec9db1d9bcec0218fb69a?d=identicon)[DrSchimke](/maintainers/DrSchimke)

---

Top Contributors

[![DrSchimke](https://avatars.githubusercontent.com/u/3299009?v=4)](https://github.com/DrSchimke "DrSchimke (41 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sci-cacheable/health.svg)

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

###  Alternatives

[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k348.9M2.5k](/packages/symfony-cache)[symfony/cache-contracts

Generic abstractions related to caching

2.4k308.9M198](/packages/symfony-cache-contracts)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[league/flysystem-cached-adapter

An adapter decorator to enable meta-data caching.

35426.9M119](/packages/league-flysystem-cached-adapter)[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)[cache/adapter-common

Common classes for PSR-6 adapters

11124.4M38](/packages/cache-adapter-common)

PHPackages © 2026

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