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

ActiveLibrary[Caching](/categories/caching)

tobento/app-cache
=================

App cache support.

2.0(9mo ago)085↓87.5%4MITPHPPHP &gt;=8.4

Since Jun 30Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/app-cache)[ Packagist](https://packagist.org/packages/tobento/app-cache)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-app-cache/feed)WikiDiscussions 2.x Synced yesterday

READMEChangelog (4)Dependencies (11)Versions (6)Used By (4)

App Cache
=========

[](#app-cache)

Cache support for the app.

Table of Contents
-----------------

[](#table-of-contents)

- [Getting Started](#getting-started)
    - [Requirements](#requirements)
- [Documentation](#documentation)
    - [App](#app)
    - [Cache Boot](#cache-boot)
        - [Cache Config](#cache-config)
        - [Cache Usage](#cache-usage)
        - [Adding and Registering Caches](#adding-and-registering-caches)
    - [Deleting Expired Items](#deleting-expired-items)
    - [Clearing Cache](#clearing-cache)
- [Credits](#credits)

---

Getting Started
===============

[](#getting-started)

Add the latest version of the app cache project running this command.

```
composer require tobento/app-cache

```

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

[](#requirements)

- PHP 8.4 or greater

Documentation
=============

[](#documentation)

App
---

[](#app)

Check out the [**App Skeleton**](https://github.com/tobento-ch/app-skeleton) if you are using the skeleton.

You may also check out the [**App**](https://github.com/tobento-ch/app) to learn more about the app in general.

Cache Boot
----------

[](#cache-boot)

The cache boot does the following:

- installs and loads cache config file
- implements PSR-6 and PSR-16 interfaces based on cache config

```
use Tobento\App\AppFactory;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\Cache\Boot\Cache::class);

// Run the app:
$app->run();
```

You may check out the [**Cache Service**](https://github.com/tobento-ch/service-cache) to learn more about it.

### Cache Config

[](#cache-config)

The configuration for the cache is located in the `app/config/cache.php` file at the default App Skeleton config location where you can specify the pools and caches for your application.

### Cache Usage

[](#cache-usage)

You can access the pools and caches in several ways:

**Using the app**

```
use Tobento\App\AppFactory;
use Tobento\Service\Cache\CacheItemPoolsInterface;
use Tobento\Service\Cache\Simple\CachesInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\SimpleCache\CacheInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\Cache\Boot\Cache::class);
$app->booting();

// PSR-6 cache:

// using the default pool:
$pool = $app->get(CacheItemPoolInterface::class);

// using the pools:
$pools = $app->get(CacheItemPoolsInterface::class);

// PSR-16 simple cache:

// using the default pool:
$cache = $app->get(CacheInterface::class);

// using the caches:
$caches = $app->get(CachesInterface::class);

// Run the app:
$app->run();
```

Check out the [**Cache Item Pools Interface**](https://github.com/tobento-ch/service-cache#cache-item-pools-interface) to learn more about it.

Check out the [**Caches Interface**](https://github.com/tobento-ch/service-cache#caches-interface) to learn more about it.

**Using autowiring**

You can also request the interfaces in any class resolved by the app:

```
use Tobento\Service\Cache\CacheItemPoolsInterface;
use Tobento\Service\Cache\Simple\CachesInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\SimpleCache\CacheInterface;

class SomeService
{
    public function __construct(
        protected CacheItemPoolsInterface $pools,
        protected CacheItemPoolInterface $pool,
        protected CachesInterface $caches,
        protected CacheInterface $cache,
    ) {}
}
```

Adding and Registering Caches
-----------------------------

[](#adding-and-registering-caches)

You may add and register more pools and caches by the following way instead of using the cache config file:

```
use Tobento\App\AppFactory;
use Tobento\Service\Cache\CacheItemPoolsInterface;
use Tobento\Service\Cache\Simple\CachesInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\SimpleCache\CacheInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// PSR-6:
$app->on(CacheItemPoolsInterface::class, function(CacheItemPoolsInterface $pools) {
    // using the add method:
    $pools->add(name: 'name', pool: $pool);

    // using the register method:
    $pools->register(
        name: 'name',
        pool: function(string $name): CacheItemPoolInterface {
            // create the pool:
            return $pool;
        },
    );
});

// PSR-16:
$app->on(CachesInterface::class, function(CachesInterface $caches) {
    // using the add method:
    $caches->add(name: 'name', cache: $cache);

    // using the register method:
    $caches->register(
        name: 'name',
        cache: function(string $name): CacheInterface {
            // create the cache:
            return $cache;
        },
    );
});

// Adding boots:
$app->boot(\Tobento\App\Cache\Boot\Cache::class);

// Run the app:
$app->run();
```

Deleting Expired Items
----------------------

[](#deleting-expired-items)

Some PSR 6 cache pools or PSR 16 caches do not include an automated mechanism for pruning expired cache items.

If you have installed the [App Console](https://github.com/tobento-ch/app-console) you may easily delete expired items running the following commands:

**PSR 6**

```
php ap cache:pool:prune

```

**PSR 16**

```
php ap cache:prune

```

If you would like to automate this process, consider installing the [App Schedule](https://github.com/tobento-ch/app-schedule) bundle and using a command task:

```
use Tobento\Service\Schedule\Task;
use Butschster\CronExpression\Generator;

$schedule->task(
    new Task\CommandTask(
        command: 'cache:pool:prune',
    )
    // schedule task:
    ->cron(Generator::create()->weekly())
);
```

Clearing Cache
--------------

[](#clearing-cache)

If you have installed the [App Console](https://github.com/tobento-ch/app-console) you may easily clear caches running the following commands:

**PSR 6**

```
php ap cache:pool:clear

```

Clearing specific pools only:

```
php ap cache:pool:clear --pool=file --pool=another

```

**PSR 16**

```
php ap cache:clear

```

Clearing specific pools only:

```
php ap cache:clear --cache=file --cache=another

```

Credits
=======

[](#credits)

- [Tobias Strub](https://www.tobento.ch)
- [All Contributors](../../contributors)

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance58

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

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

Recently: every ~147 days

Total

6

Last Release

276d ago

Major Versions

1.x-dev → 2.02025-10-01

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/055d6a1b5c2384bb179c75ab0b55914231d898fdc4dffeb30770f81200e52206?d=identicon)[TOBENTOch](/maintainers/TOBENTOch)

---

Top Contributors

[![tobento-ch](https://avatars.githubusercontent.com/u/16684832?v=4)](https://github.com/tobento-ch "tobento-ch (9 commits)")

---

Tags

packagecacheapptobento

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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