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

ActiveLibrary[Caching](/categories/caching)

phpnomad/cache
==============

1.0.3(3w ago)06.2k↓34.2%1[1 issues](https://github.com/phpnomad/cache/issues)[3 PRs](https://github.com/phpnomad/cache/pulls)5MITPHPCI failing

Since Dec 18Pushed 3w ago2 watchersCompare

[ Source](https://github.com/phpnomad/cache)[ Packagist](https://packagist.org/packages/phpnomad/cache)[ Docs](https://github.com/phpnomad/core)[ RSS](/packages/phpnomad-cache/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (4)Dependencies (8)Versions (12)Used By (5)

phpnomad/cache
==============

[](#phpnomadcache)

[![Latest Version](https://camo.githubusercontent.com/bbfdbd598df1c95b6799057f47403c98b7fb03b55cd0d9580bb2adfc4e7b2809/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f63616368652e737667)](https://packagist.org/packages/phpnomad/cache)[![Total Downloads](https://camo.githubusercontent.com/8bad993c6b0f6ad0dcc1c24c57911125bddbe7ca97906d420284c21e3e57bd78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f63616368652e737667)](https://packagist.org/packages/phpnomad/cache)[![PHP Version](https://camo.githubusercontent.com/388c80a7401c395ac1ab1232bdc49d185667cbfbd5c3f079229476e408d6ee3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f63616368652e737667)](https://packagist.org/packages/phpnomad/cache)[![License](https://camo.githubusercontent.com/9b9403c0f4fc59bb8dd9d7f8e88f7be5a87c1d3b3ca0a5868b5d3eb6c637bdb2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f63616368652e737667)](https://packagist.org/packages/phpnomad/cache)

`phpnomad/cache` defines the caching contract for PHPNomad applications. It gives you a backend-agnostic `CacheStrategy` interface, a `CachePolicy` contract for deciding what gets cached and for how long, a `CacheableService` that wires the two together with event broadcasting, and helpers for key generation and in-memory instance caching.

The package itself is an abstraction. The concrete backend comes from an integration package like `phpnomad/symfony-cache-integration`, which adapts Symfony's Cache component to this interface. Your application code depends only on the interface, so swapping the backend later never touches your business logic. The cache layer in this package powers [Siren](https://sirenaffiliates.com) and other production PHPNomad apps.

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

[](#installation)

```
composer require phpnomad/cache
```

You will also need a concrete cache backend such as `phpnomad/symfony-cache-integration` bound to `CacheStrategy` in your container.

Quick Start
-----------

[](#quick-start)

Inject `CacheStrategy` into any service that needs a read-through cache. The interface exposes `get`, `set`, `exists`, `delete`, and `clear`. A miss on `get` throws `CachedItemNotFoundException`, which you catch to fall back to your source of truth.

```
