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

ActiveLibrary[Caching](/categories/caching)

contenir/cache
==============

Framework-agnostic page-cache control for Contenir CMS — admin writes a purge signal, Sites read it and flush.

v0.1.1(1mo ago)09MITPHPPHP ^8.1 || ^8.2 || ^8.3

Since May 6Pushed 1mo agoCompare

[ Source](https://github.com/contenir/cache)[ Packagist](https://packagist.org/packages/contenir/cache)[ RSS](/packages/contenir-cache/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

contenir/cache
==============

[](#contenircache)

Framework-agnostic page-cache control for [Contenir CMS](https://github.com/contenir).

The CMS lets an operator toggle page caching on or off, decide which request signals participate in cache-key generation (query/post/session/files/cookie), and exclude specific URL patterns. The consuming Site (Mezzio, Laminas MVC, anything else) reads those settings on every request and applies them in its caching layer.

This package provides the *domain* — an immutable state value plus a repository interface, with file-based and in-memory implementations. Framework-specific listeners come from sibling packages (e.g. `contenir/cache-laminas-mvc`).

Install
-------

[](#install)

```
composer require contenir/cache
```

Add `contenir/config` if you intend to use `Repository\FileRepository` (admin-side writer). Sites that read state from the merged Laminas/Mezzio config — and use `Repository\InMemoryRepository` in tests — don't need it.

Usage
-----

[](#usage)

### Reading state

[](#reading-state)

```
use Contenir\Cache\Repository\FileRepository;

$repo = new FileRepository('/var/www/shared/pagecache.local.php');
$state = $repo->get();

if ($state->enabled) {
    // Apply cache options ($state->options) and route overrides ($state->routes)
}
```

### Writing state (admin)

[](#writing-state-admin)

```
use Contenir\Cache\CacheControl;

$repo->save(new CacheControl(
    enabled: true,
    options: ['cache_with_query' => true, 'cache_with_session' => false],
    routes:  ['/api.*' => ['cache' => false]],
));
```

### File format

[](#file-format)

`FileRepository` reads and writes a PHP file under the `pagecache` namespace, so the same file can be merged directly into a Laminas/Mezzio site config:

```
