PHPackages                             henzeb/laravel-pennant-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. henzeb/laravel-pennant-cache

ActiveLibrary[Caching](/categories/caching)

henzeb/laravel-pennant-cache
============================

A Pennant driver built on Laravel's Cache

v0.1(1mo ago)00MITPHPPHP ^8.2CI passing

Since Jul 10Pushed 1mo agoCompare

[ Source](https://github.com/henzeb/laravel-pennant-cache)[ Packagist](https://packagist.org/packages/henzeb/laravel-pennant-cache)[ Docs](https://github.com/henzeb/laravel-pennant-cache)[ RSS](/packages/henzeb-laravel-pennant-cache/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Cache driver for Laravel Pennant
================================

[](#cache-driver-for-laravel-pennant)

[![Build Status](https://github.com/henzeb/laravel-pennant-cache/workflows/tests/badge.svg)](https://github.com/henzeb/laravel-pennant-cache/actions)[![Latest Version on Packagist](https://camo.githubusercontent.com/7b275ec9443f010fc23337a1c2e905951be60bd794bc18efedeb077a160d9b00/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68656e7a65622f6c61726176656c2d70656e6e616e742d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/henzeb/laravel-pennant-cache)[![Total Downloads](https://camo.githubusercontent.com/6e6ad1186e85bd83f0cf467c16be0dbbdb091232faaabb936dc9ac657e79c42c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68656e7a65622f6c61726176656c2d70656e6e616e742d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/henzeb/laravel-pennant-cache)[![License](https://camo.githubusercontent.com/3e56ac8ba9c75ad16d98539c3e1cc7376094132ad494ddcb5fe243beece9603a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68656e7a65622f6c61726176656c2d70656e6e616e742d6361636865)](https://packagist.org/packages/henzeb/laravel-pennant-cache)

This package adds a `cache` driver for [Laravel Pennant](https://laravel.com/docs/master/pennant) that stores feature flag values using any Laravel cache store, e.g. `redis`, `memcached`, `dynamodb` or `array`.

Why
---

[](#why)

Pennant ships with `array` and `database` drivers out of the box, and both are good at what they're meant for: `array` is great for testing since it never persists beyond a single request, and `database` is a solid production option, storing every feature value in its own table. This driver is just another option for when you'd rather reuse a cache store you already have running — `store` can point at any store your `config/cache.php` defines, including its own `database` cache store, so this doesn't have to mean giving up a database backend either.

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

[](#installation)

```
composer require henzeb/laravel-pennant-cache
```

Add a `cache` entry to the `stores` section of `config/pennant.php`, pointing `store` at whichever cache store (as configured in `config/cache.php`) should hold the feature values:

```
'stores' => [
    'cache' => [
        'driver' => 'cache',
        'store' => 'redis',
    ],
],
```

> **Tip:** consider pointing `store` at a cache store dedicated to Pennant rather than reusing your app's default one, so feature flags aren't flushed by a stray `Cache::flush()` or evicted to make room for unrelated cache entries. For example, define a separate `redis` store in `config/cache.php` using its own connection/database:
>
> ```
> 'stores' => [
>     'pennant' => [
>         'driver' => 'redis',
>         'connection' => 'pennant',
>     ],
> ],
> ```
>
>
>
> and point this driver at it: `'store' => 'pennant'`.

Configuration
-------------

[](#configuration)

KeyDefaultDescription`store`app's default cache storeThe name of the cache store (from `config/cache.php`) to read and write feature values from.`prefix``pennant`Prefix used for every cache key this driver writes, to avoid colliding with unrelated cache keys.`index``{prefix}:index`Cache key used to keep track of which feature/scope pairs have been stored, for `stored()` and `purge()`. Set this explicitly if you run more than one `cache` store against the same underlying cache store, so their indexes don't collide.`ttl``null` (forever)Seconds until a stored feature value expires. Left at `null`, values are stored with `forever()` and only disappear when deleted, purged, or evicted by the cache store itself (e.g. Redis under memory pressure).```
'stores' => [
    'cache' => [
        'driver' => 'cache',
        'store' => 'redis',
        'prefix' => 'my-app-features',
        'ttl' => 3600,
    ],
],
```

Activating/deactivating without losing the payload
--------------------------------------------------

[](#activatingdeactivating-without-losing-the-payload)

Usually, when you have a feature flag with a payload, deactivating it means losing that payload — activating it again means setting the payload again from scratch. This driver treats a plain `true`/`false` (what `Feature::activate()` and `::deactivate()` pass along) purely as an on/off toggle, and keeps the previously stored payload untouched, so a feature can be switched off and back on without losing its data:

```
Feature::store('cache')->for($user)->activate('discount', ['percentage' => 10]);

Feature::store('cache')->for($user)->deactivate('discount');
Feature::store('cache')->for($user)->value('discount'); // false

Feature::store('cache')->for($user)->activate('discount');
Feature::store('cache')->for($user)->value('discount'); // ['percentage' => 10] again
```

Passing an actual payload (anything other than a literal `true`/`false`) always overwrites the stored value, regardless of whether the feature was active or not. If a feature is activated for the very first time with no payload of its own, and it has a `Feature::define()` resolver whose default is itself a payload (not a plain boolean), that default is used instead of an empty value.

> **Note:** Pennant's own `Decorator` keeps a local, per-request memoization of every value it reads or writes, and assumes the value it just wrote is exactly the value it will read back. Because this driver can return a different, previously stored payload than what was just passed to `activate()`/`deactivate()`, that assumption doesn't hold within the same request. In practice this rarely matters — Pennant flushes that local cache at the start of every request/queued job/Octane tick — but if you activate/deactivate and immediately read the value back within the same request (e.g. in a test), call `Feature::flushCache()` in between to see the driver's real state rather than the Decorator's stale local copy.

Testing this package
--------------------

[](#testing-this-package)

```
composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Henze Berkheij](https://github.com/henzeb)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 74% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

48d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15928532?v=4)[henzeb](/maintainers/henzeb)[@henzeb](https://github.com/henzeb)

---

Top Contributors

[![henzeb](https://avatars.githubusercontent.com/u/15928532?v=4)](https://github.com/henzeb "henzeb (1 commits)")

---

Tags

laravelcacheflagspennantfeature-flagsfeature-toggleshenzebtogglescache driverfeature managementcache store

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/henzeb-laravel-pennant-cache/health.svg)

```
[![Health](https://phpackages.com/badges/henzeb-laravel-pennant-cache/health.svg)](https://phpackages.com/packages/henzeb-laravel-pennant-cache)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975175.4k2](/packages/awssat-laravel-visits)[swayok/alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202600.2k9](/packages/swayok-alternative-laravel-cache)[offload-project/laravel-toggle

A simple and flexible feature toggle (feature flag) package for Laravel

282.7k](/packages/offload-project-laravel-toggle)[dragon-code/laravel-cache

An improved interface for working with cache

7146.5k10](/packages/dragon-code-laravel-cache)[henzeb/laravel-cache-index

Flexible replacement for tags

1217.0k](/packages/henzeb-laravel-cache-index)[gabrielmoura/laravel-pennant-redis

A Redis Driver for Laravel Pennant

165.0k](/packages/gabrielmoura-laravel-pennant-redis)

PHPackages © 2026

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