PHPackages                             swayok/alternative-laravel-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. swayok/alternative-laravel-cache

ActiveLibrary[Caching](/categories/caching)

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/

6.1.17(1y ago)202541.1k↑19.5%30[7 issues](https://github.com/swayok/alternative-laravel-cache/issues)6MITPHPPHP &gt;=7.2.5

Since Sep 5Pushed 1y ago5 watchersCompare

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

READMEChangelog (10)Dependencies (8)Versions (37)Used By (6)

What is this?
=============

[](#what-is-this)

This is full-featured replacement for Laravel's Redis and file cache storages. All storages support proper tagging. Cache pools provided by  + I've added `HierarchialFilesystemCachePool` based on code of `FilesystemCachePool` provided by . All classes in this lib are proxies between Laravel's cache system and cache pools from . I do not have any relation to php-cache.com and any cache pools there. And in result I cannot fix or change anything to the way cache pools are working.

What is proper tagging?
-----------------------

[](#what-is-proper-tagging)

For example, you have:

```
Cache::tags(['tag1', 'tag2'])->put('tag-test1', 'ok', 20);

```

How Laravel's native cache works with tags and Redis (Laravel 5.2):

```
Cache::tags(['tag1', 'tag2'])->get('tag-test1');    //< 'ok'
Cache::tags(['tag2', 'tag1'])->get('tag-test1');    //< null
Cache::tags(['tag1'])->get('tag-test1');            //< null
Cache::tags(['tag2'])->get('tag-test1');            //< null
Cache::get('tag-test1');                            //< null
Cache::forget('tag-test1');                         //< won't delete anything
Cache::tags(['tag1', 'tag2'])->forget('tag-test1'); //< deleted
Cache::tags(['tag2', 'tag1'])->forget('tag-test1'); //< won't delete anything
Cache::tags(['tag1'])->forget('tag-test1');         //< won't delete anything
Cache::tags(['tag2'])->forget('tag-test1');         //< won't delete anything
Cache::tags(['tag1'])->flush();                     //< won't delete anything
Cache::tags(['tag2'])->flush();                     //< won't delete anything
Cache::tags(['tag1', 'tag2'])->flush();             //< flushed
Cache::tags(['tag2', 'tag1'])->flush();             //< won't delete anything

```

If you think that this is correct behavior - go away, you don't need this lib.

I was quite confused when attempted to use Laravel's version of tagging. Laravel's version works like folders (hierarchial cache), but not like tags. I tried to understand for what purpose Laravel's tagging can be used and haven't found any. It's totally useless in almost any situation. Hopefully there are compatible drivers provided by .

How it works with this lib:

```
Cache::tags(['tag1', 'tag2'])->get('tag-test1');    //< 'ok' - use Cache::get('tag-test1') instead
Cache::tags(['tag2', 'tag1'])->get('tag-test1');    //< 'ok' - use Cache::get('tag-test1') instead
Cache::tags(['tag1'])->get('tag-test1');            //< 'ok' - use Cache::get('tag-test1') instead
Cache::tags(['tag2'])->get('tag-test1');            //< 'ok' - use Cache::get('tag-test1') instead
Cache::get('tag-test1');                            //< 'ok'
Cache::forget('tag-test1');                         //< deleted
Cache::tags(['tag1', 'tag2'])->forget('tag-test1'); //< deleted - use Cache::forget('tag-test1') instead
Cache::tags(['tag2', 'tag1'])->forget('tag-test1'); //< deleted - use Cache::forget('tag-test1') instead
Cache::tags(['tag1'])->forget('tag-test1');         //< deleted - use Cache::forget('tag-test1') instead
Cache::tags(['tag2'])->forget('tag-test1');         //< deleted - use Cache::forget('tag-test1') instead
Cache::tags(['tag1'])->flush();                     //< deleted all cache entries with tag 'tag1'
Cache::tags(['tag2'])->flush();                     //< deleted all cache entries with tag 'tag2'
Cache::tags(['tag1', 'tag2'])->flush();             //< deleted all cache entries with tag 'tag1' or 'tag2'
Cache::tags(['tag2', 'tag1'])->flush();             //< deleted all cache entries with tag 'tag2' or 'tag1'

```

Note that tags here is like soft grouping for cache entries. This means that you do not need to specify tags to access/set/delete certain cache key. Cache key is the only thing you need to know to do this. Tags purpose is to give you a possibility to delete lots of cache entries with one line of code. Tags are very useful when you need to store lots of entries related to same group and delete all cache entries at once when something changes.

For example:

1. You cache database records from `users` table in many places around you project tagging them with `users` tag.
2. You cache database records from `orders` table tagging them with both `users` and `orders` tags.
3. Some user updates his data and this action invalidates all cache entries related to this user and `users` table.
4. You need to remove all cache entries related to `users` (1 and 2) and you can do this just like this: `Cache::tags(['users'])->flush();`.

This way all cache entries created in 1 and 2 will be removed. And you won't need to know tags to access any cache entry by its key.

How to use it:
--------------

[](#how-to-use-it)

### For Laravel 10+

[](#for-laravel-10)

Add to `composer.json`:

```
"require": {
    "swayok/alternative-laravel-cache": "6.1.*"
}

```

### For Laravel 5.4+

[](#for-laravel-54)

Add to `composer.json`:

```
"require": {
    "swayok/alternative-laravel-cache": "5.4.*"
}

```

### For Laravel 5.3

[](#for-laravel-53)

Add to `composer.json`:

```
"require": {
    "swayok/alternative-laravel-cache": "5.3.*"
}

```

### Filesystem support

[](#filesystem-support)

Add to `composer.json`:

```
"require": {
    "swayok/cache-filesystem-adapter": "^1.0.0"
}

```

### Redis support

[](#redis-support)

To use `predis` add to `composer.json`:

```
"require": {
    "cache/predis-adapter": "^1.0"
}

```

To use `php-redis` extension add to `composer.json:

```
"require": {
    "ext-redis": "*",
    "cache/redis-adapter": "^1.0"
}

```

### Memcached support (NOT supported in Windows!)

[](#memcached-support-not-supported-in-windows)

Add to `composer.json`:

```
"require": {
    "ext-memcached": "*",
    "cache/memcached-adapter": "^1.0"
}

```

For Windows there are only `memcache` extension (without D at the end) but there are no such driver in Laravel.

### Declare ServiceProvider

[](#declare-serviceprovider)

### For Laravel 5.6+

[](#for-laravel-56)

Package auto-discovery will work.

### For Laravel &lt; 5.6

[](#for-laravel--56)

Add to `config/app.php`:

```
$providers = [
    \AlternativeLaravelCache\Provider\AlternativeCacheStoresServiceProvider::class,
]

```

### Supported cache drivers

[](#supported-cache-drivers)

- `redis` - redis cache with proper tagging, also supports hierarchical cache keys;
- `memcached` - memcached cache with proper tagging, also supports hierarchical cache keys;
- `file` - simple file-based cache with proper tagging;
- `hierarchial_file` - hierarchical file-based cache with proper tagging. This driver also supports `/` instead of `|` so you can use `/users/:uid/followers/:fid/likes` instead of `|users|:uid|followers|:fid|likes`as it better represents path in file system.

Pipe character `|` in cache key (hierarchical cache keys)
---------------------------------------------------------

[](#pipe-character--in-cache-key-hierarchical-cache-keys)

Pipe character `|` for `redis`, `memcached` and `hierarchial_file` drivers works as hierarchy separator. This means that cache keys that contain `|` will work as hierarchy. Detals here:

```
// Put key with colons (treated as usual cache key)
Cache::put('cache-key:something:something-else', 'value', now()->addHours(6));

// Put key with pipes (treated as hierarchical cache key)
Cache::put('cache-key|something|something-else', 'value', now()->addHours(6));

// Get key with colons
Cache::get('cache-key:something:something-else');
"value"

// Get key with pipes
Cache::get('cache-key|something|something-else');
"value"

// Forget call (it will both remove the cache key called 'cache-key' and whole hierarchy)
Cache::forget('cache-key');

// Get key with colons
Cache::get('cache-key:something:something-else');
"value"

// Get key with pipes
Cache::get('cache-key|something|something-else');
null

```

Slash character `/` in cache key
--------------------------------

[](#slash-character--in-cache-key)

Slash character `/` for `hierarchial_file` driver works as hierarchy separator like pipe character `|`. This was added to mimic folder structure.

### `permissions` configuration parameter for file-based cache drivers (`config/cache.php`)

[](#permissions-configuration-parameter-for-file-based-cache-drivers-configcachephp)

```
'stores' => [
    'file' => [
        'driver' => 'file',
        'path' => storage_path('framework/cache/data'),
        'permissions' => [
            'file' => [
                'public' => 0644,
            ],
            'dir' => [
                'public' => 0755,
            ],
        ]
    ],
],

```

These permissions passed to `vendor/league/flysystem/src/Adapter/Local.php`and merged with default permissions. There are 2 types: `public` and `private`but only `public` permissions will be used in `AlternativeLaravelCache`.

Notes
-----

[](#notes)

By default, service provider will replace Laravel's `redis` and `file` cache stores. You can alter this behavior like this:

```
class MyAlternativeCacheStoresServiceProvider extends AlternativeCacheStoresServiceProvider {
    static protected $redisDriverName = 'altredis';
    static protected $memcacheDriverName = 'altmemcached';
    static protected $fileDriverName = 'altfile';
}

```

File cache storage currently supports only `'driver' => 'file'`. You can extend list of file cache drivers by
overwriting `AlternativeCacheStoresServiceProvider->makeFileCacheAdapter()`.

Yep, there are not many tests right now and possibly there will never be more.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity55

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 78.3% 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 ~91 days

Total

33

Last Release

603d ago

Major Versions

5.4.13 → 6.0.02021-02-09

PHP version history (5 changes)5.3.1PHP &gt;=5.6

5.4.13PHP ^5.6 || ^7.0

6.0.0PHP ^7.2.5|^8.0

6.1.3PHP ^7.2.5|^8.0|^8.1

6.1.10PHP &gt;=7.2.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a631e17770f1ef26d05cbc896e14b218d186973a00a515eed2d86fbc9eb936a?d=identicon)[sway](/maintainers/sway)

---

Top Contributors

[![swayok](https://avatars.githubusercontent.com/u/629675?v=4)](https://github.com/swayok "swayok (65 commits)")[![rogervila](https://avatars.githubusercontent.com/u/6053012?v=4)](https://github.com/rogervila "rogervila (6 commits)")[![benallfree](https://avatars.githubusercontent.com/u/1068356?v=4)](https://github.com/benallfree "benallfree (4 commits)")[![Macek007](https://avatars.githubusercontent.com/u/10949306?v=4)](https://github.com/Macek007 "Macek007 (1 commits)")[![Malezha](https://avatars.githubusercontent.com/u/3649525?v=4)](https://github.com/Malezha "Malezha (1 commits)")[![mattsches](https://avatars.githubusercontent.com/u/68414?v=4)](https://github.com/mattsches "mattsches (1 commits)")[![mnishihan](https://avatars.githubusercontent.com/u/1173288?v=4)](https://github.com/mnishihan "mnishihan (1 commits)")[![NikolayMurha](https://avatars.githubusercontent.com/u/1524144?v=4)](https://github.com/NikolayMurha "NikolayMurha (1 commits)")[![plastique](https://avatars.githubusercontent.com/u/2137593?v=4)](https://github.com/plastique "plastique (1 commits)")[![J5Dev](https://avatars.githubusercontent.com/u/2751683?v=4)](https://github.com/J5Dev "J5Dev (1 commits)")[![denisrpriebe](https://avatars.githubusercontent.com/u/8739001?v=4)](https://github.com/denisrpriebe "denisrpriebe (1 commits)")

---

Tags

phplaravelcacheredis-cachetagged cacheredis tagged cache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/swayok-alternative-laravel-cache/health.svg)

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

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[alexmg86/laravel-sub-query

Laravel subquery

7538.4k](/packages/alexmg86-laravel-sub-query)[cache/illuminate-adapter

A PSR-6 cache implementation using Illuminate. This implementation supports tags

1177.6k2](/packages/cache-illuminate-adapter)[byerikas/cache-tags

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

1413.9k](/packages/byerikas-cache-tags)[antennaio/laravel-clyde

Image uploads and manipulation for Laravel, a wrapper around Glide

292.6k](/packages/antennaio-laravel-clyde)

PHPackages © 2026

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