PHPackages                             trevorpe/laravel-symfony-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. trevorpe/laravel-symfony-cache

ActiveLibrary[Caching](/categories/caching)

trevorpe/laravel-symfony-cache
==============================

Use Symfony's Cache bundle with Laravel

v2.0.0(3mo ago)1406[1 issues](https://github.com/trevorpe/laravel-symfony-cache/issues)MITPHPPHP &gt;=8.2 &lt;8.5CI passing

Since Feb 3Pushed 3mo ago1 watchersCompare

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

READMEChangelog (8)Dependencies (4)Versions (13)Used By (0)

[![Test](https://github.com/trevorpe/laravel-symfony-cache/actions/workflows/test.yml/badge.svg)](https://github.com/trevorpe/laravel-symfony-cache/actions/workflows/test.yml)

Symfony Cache for Laravel
=========================

[](#symfony-cache-for-laravel)

Use the [Symfony Cache Component](https://symfony.com/components/Cache) with Laravel's cache system. Heavily inspired by the [alternative-laravel-cache](https://github.com/swayok/alternative-laravel-cache)project.

Caution

Symfony's Cache component behaves differently than Laravel's.

Read the [Tag Behavior](#tag-behavior) and [Clear Behavior](#clear-behavior) sections before replacing the default Laravel cache stores with this library, and consider how a different tag behavior could affect any other libraries that you use.

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

[](#requirements)

- Laravel 11.x or greater
- Symfony Cache 7.4 or greater

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

[](#installation)

```
composer require trevorpe/laravel-symfony-cache

```

Usage
-----

[](#usage)

This library introduces a new cache driver registered with Laravel's `CacheManager`.

You can use a Symfony cache adapter by specifying `symfony` as your cache driver alongside an `adapter` property, with the fully-qualified class name of the Symfony cache adapter you'd like to use.

### Configuration Examples

[](#configuration-examples)

#### Array

[](#array)

```
// config/cache.php

return [
    'stores' => [
        'file' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\ArrayAdapter::class,
        ],
    ]
]
```

#### Filesystem

[](#filesystem)

```
// config/cache.php

return [
    'stores' => [
        'file' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\FilesystemAdapter::class,
            'path' => storage_path('framework/cache/data')
        ],
    ]
]
```

#### Filesystem (Tagged)

[](#filesystem-tagged)

```
// config/cache.php

return [
    'stores' => [
        'file' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter::class,
            'path' => storage_path('framework/cache/data')
        ],
    ]
]
```

#### Redis

[](#redis)

```
// config/cache.php

return [
    'stores' => [
        'redis' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\RedisAdapter::class,
            'connection' => env('REDIS_CACHE_CONNECTION', 'cache')
        ],
    ]
]
```

#### Redis (Tagged)

[](#redis-tagged)

```
// config/cache.php

return [
    'stores' => [
        'redis' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\RedisTagAwareAdapter::class,
            'connection' => env('REDIS_CACHE_CONNECTION', 'cache')
        ],
    ]
]
```

Tag Behavior
------------

[](#tag-behavior)

Similar to [alternative-laravel-cache](https://github.com/swayok/alternative-laravel-cache), this library brings an alternate tag behavior than Laravel's default cache.

Symfony's cache system does not treat tags as hierarchical like Laravel's cache system does. Instead, tagging a cache entry with one or more tags allows you to invalidate a group of entries all at once by referencing its tag. In addition, each tag is applied individually, rather than as an ordered list. (E.g. applying two tags and calling `flush()` with *either* of those tags will invalidate the entry.)

This means that tagging is only really useful when writing or removing data. Reading tagged data will function identically to getting a cache entry by its key without tags.

### Examples

[](#examples)

```
Cache::set('test-key1', 'test-value1'); // Set the item without tags

Cache::get('test-key1'); // Gets the cache item normally
Cache::tags('tag1')->get('test-key1'); // Gets the cache item normally (unaffected by tags)

Cache::tags('tag1')->flush(); // Flushes nothing, as no values are tagged.
Cache::get('test-key1'); // Value is still present

Cache::flush(); // Flushes all cache entries normally
Cache::get('test-key1'); // Value has been removed

// --------------

Cache::tags('tag2')->set('test-key2', 'test-value2'); // Sets the item with a tag

Cache::get('test-key2'); // Gets the cache item normally
Cache::tags('tag2')->get('test-key2'); // Gets the cache item normally (unaffected by tags)

Cache::tags('tag2')->flush(); // Flushes only entries tagged with 'tag2'
Cache::flush(); // Flushes all cache entries normally

Cache::get('test-key2'); // Value will have been removed by either of the above flush() calls

// --------------

Cache::tags('tag3', 'tag4')->set('test-key3', 'test-value3'); // Sets the item with a tag

Cache::get('test-key3'); // Gets the cache item normally
Cache::tags('tag3')->get('test-key3'); // Unaffected. Gets the cache item normally

Cache::tags('tag3')->flush(); // Flushes only entries tagged with 'tag3'
Cache::tags('tag4')->flush(); // Flushes only entries tagged with 'tag4'
Cache::tags('tag3', 'tag4')->flush(); // Flushes only entries tagged with 'tag3' _or_ 'tag4'
Cache::flush(); // Flushes all cache entries normally

Cache::get('test-key3'); // Value will have been removed by any of the above flush() calls
```

Clear Behavior
--------------

[](#clear-behavior)

The `clear()` method of Laravel will clear the entire cache when using Redis as the driver (and possibly others).

With Symfony's cache system, `clear()` will only clear keys matching the prefix and namespace. This is a bit less dangerous, but one should be still be cautious when clearing a cache store to ensure you are only deleting the intended values.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance62

Regular maintenance activity

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

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

Recently: every ~92 days

Total

8

Last Release

94d ago

Major Versions

v1.5.0 → v2.0.02026-02-08

PHP version history (4 changes)v1.0PHP &gt;=8.2

v1.1PHP &gt;=8.1

v1.5.0PHP &gt;=8.1 &lt;8.5

v2.0.0PHP &gt;=8.2 &lt;8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c3341acef8ef42d957c538001c4aad41cbf29015a2799b0f802e56139d80265?d=identicon)[trevorpe](/maintainers/trevorpe)

---

Top Contributors

[![trevorpe](https://avatars.githubusercontent.com/u/3450826?v=4)](https://github.com/trevorpe "trevorpe (121 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/trevorpe-laravel-symfony-cache/health.svg)

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

###  Alternatives

[rikudou/psr6-dynamo-db-bundle

PSR-6 and PSR-16 cache implementation using AWS DynamoDB for Symfony

2077.8k](/packages/rikudou-psr6-dynamo-db-bundle)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)

PHPackages © 2026

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