PHPackages                             philiprehberger/laravel-cache-toolkit - 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. philiprehberger/laravel-cache-toolkit

ActiveLibrary[Caching](/categories/caching)

philiprehberger/laravel-cache-toolkit
=====================================

Standardized cache key builder and tag-aware cache operations for Laravel with graceful fallback for non-tagging drivers

v1.0.5(3mo ago)160MITPHPPHP ^8.2CI passing

Since Mar 6Pushed 1mo agoCompare

[ Source](https://github.com/philiprehberger/laravel-cache-toolkit)[ Packagist](https://packagist.org/packages/philiprehberger/laravel-cache-toolkit)[ Docs](https://github.com/philiprehberger/laravel-cache-toolkit)[ RSS](/packages/philiprehberger-laravel-cache-toolkit/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (20)Versions (7)Used By (0)

Laravel Cache Toolkit
=====================

[](#laravel-cache-toolkit)

[![Tests](https://github.com/philiprehberger/laravel-cache-toolkit/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/laravel-cache-toolkit/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/34688c9fb1f81ccf409b772c870c2f49b61200d2cac812c79c6b0fe583381c5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f6c61726176656c2d63616368652d746f6f6c6b69742e737667)](https://packagist.org/packages/philiprehberger/laravel-cache-toolkit)[![Last updated](https://camo.githubusercontent.com/bfe7a6854560ea8f0dfd19db2c124780b7507deef017d5e5fbfc155f9685892f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7068696c69707265686265726765722f6c61726176656c2d63616368652d746f6f6c6b6974)](https://github.com/philiprehberger/laravel-cache-toolkit/commits/main)

Standardized cache key builder and tag-aware cache operations for Laravel with graceful fallback for non-tagging drivers.

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

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

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

[](#installation)

```
composer require philiprehberger/laravel-cache-toolkit
```

The service provider is auto-discovered by Laravel. Optionally publish the config file:

```
php artisan vendor:publish --tag=cache-toolkit-config
```

This places `config/cache-toolkit.php` into your application.

Usage
-----

[](#usage)

### CacheKeyBuilder

[](#cachekeybuilder)

`CacheKeyBuilder` is a static utility class for building consistent, predictable cache keys.

```
use PhilipRehberger\CacheToolkit\CacheKeyBuilder;

CacheKeyBuilder::make('client', '123', 'stats');
// "client:123:stats"

CacheKeyBuilder::forModel($client, 'details');
// "client:42:details"

CacheKeyBuilder::forList('clients', ['active' => 1]);
// "clients:list:"

CacheKeyBuilder::forPaginated('clients', page: 2, perPage: 15);
// "clients:page:2:15:all"

CacheKeyBuilder::forAnalytics('revenue', '2026-01-01', '2026-03-31');
// "analytics:revenue:2026-01-01:2026-03-31"

CacheKeyBuilder::forUser(userId: 5, type: 'dashboard');
// "user:5:dashboard"
```

### CacheTagManager

[](#cachetagmanager)

`CacheTagManager` wraps Laravel's Cache facade with tag-aware operations. When the driver does not support tags (file, array, database) all operations fall back transparently to plain cache calls.

```
use PhilipRehberger\CacheToolkit\Facades\CacheTag;

$value = CacheTag::remember(
    ttlKey:   'dashboard_stats',
    callback: fn () => expensiveQuery(),
    tags:     ['clients'],
    'client', '42', 'stats'
);

CacheTag::put($key, $data, ttl: 300, tags: ['clients']);
CacheTag::get($key, tags: ['clients']);
CacheTag::forget($key, tags: ['clients']);
CacheTag::flush(['clients']);
CacheTag::flushType('clients');
```

### Configuration

[](#configuration)

```
// config/cache-toolkit.php
return [
    'prefixes' => [],
    'ttl' => [
        'default' => 300,
        'short'   => 60,
        'medium'  => 900,
        'long'    => 3600,
        'daily'   => 86400,
    ],
    'tags' => [],
];
```

API
---

[](#api)

### CacheKeyBuilder

[](#cachekeybuilder-1)

MethodDescriptionReturns`CacheKeyBuilder::make(string ...$parts)`Build a key from arbitrary parts (empty parts filtered)`string``CacheKeyBuilder::forModel(Model $model, string ...$suffix)`Build a key from a model instance`string``CacheKeyBuilder::forModelType(string $class, int|string $id, string ...$suffix)`Build a key from a class name and ID`string``CacheKeyBuilder::forList(string $type, array $filters = [])`Build a list key with optional filter hash`string``CacheKeyBuilder::forPaginated(string $type, int $page, int $perPage, array $filters = [])`Build a paginated list key`string``CacheKeyBuilder::forAnalytics(string $type, ?string $from = null, ?string $to = null)`Build an analytics key`string``CacheKeyBuilder::forUser(int $userId, string $type)`Build a user-scoped key`string``CacheKeyBuilder::forDateRange(string $type, string $from, string $to)`Build a date-range key`string``CacheKeyBuilder::ttl(string $key)`Get TTL in seconds from config`int``CacheKeyBuilder::ttlCarbon(string $key)`Get TTL as Carbon instance`DateTimeInterface``CacheKeyBuilder::tags(string $type)`Get tag array from config`string[]``CacheKeyBuilder::supportsTags()`Check if current driver supports tags`bool`### CacheTagManager

[](#cachetagmanager-1)

MethodDescriptionReturns`->remember(string $ttlKey, callable $callback, array $tags, string ...$keyParts)`Get or store a value`mixed``->put(string $key, mixed $value, int $ttl, array $tags = [])`Store a value`void``->get(string $key, array $tags = [])`Retrieve a value`mixed``->has(string $key, array $tags = [])`Check existence`bool``->forget(string $key, array $tags = [])`Remove a value`void``->flush(array $tags)`Flush all entries for given tags`bool``->flushType(string $type)`Flush entries for a config-defined type`bool``->flushTypes(string[] $types)`Flush multiple config-defined types`bool[]`### Tag Driver Support

[](#tag-driver-support)

DriverTags SupportedBehaviour`redis`YesTags used for grouping and invalidation`memcached`YesTags used for grouping and invalidation`file`NoFalls back to plain cache; `flush` returns `false``array`NoFalls back to plain cache; `flush` returns `false``database`NoFalls back to plain cache; `flush` returns `false`Development
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

Support
-------

[](#support)

If you find this project useful:

⭐ [Star the repo](https://github.com/philiprehberger/laravel-cache-toolkit)

🐛 [Report issues](https://github.com/philiprehberger/laravel-cache-toolkit/issues?q=is%3Aissue+is%3Aopen+label%3Abug)

💡 [Suggest features](https://github.com/philiprehberger/laravel-cache-toolkit/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)

❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)

🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)

💻 [GitHub Profile](https://github.com/philiprehberger)

🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance87

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.8% 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 ~3 days

Total

6

Last Release

96d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (15 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laravelrediscachememcachedtagskey-builder

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-laravel-cache-toolkit/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.7M64](/packages/spatie-laravel-responsecache)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k14.1M122](/packages/laravel-pulse)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k55.1k1](/packages/mike-bronner-laravel-model-caching)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9742.3M121](/packages/roots-acorn)[propaganistas/laravel-disposable-email

Disposable email validator

6012.9M7](/packages/propaganistas-laravel-disposable-email)

PHPackages © 2026

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