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.4(4d ago)116MITPHPPHP ^8.2CI passing

Since Mar 6Pushed yesterdayCompare

[ 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 today

READMEChangelogDependencies (10)Versions (6)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)[![License](https://camo.githubusercontent.com/d03d31182ddd36b6e83c16e613082bf817e22b44d627a0f1c3cbddaf4cb4af8c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f6c61726176656c2d63616368652d746f6f6c6b6974)](LICENSE)

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
```

License
-------

[](#license)

MIT

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance100

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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

Total

5

Last Release

4d 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 (9 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

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

981161.4k2](/packages/awssat-laravel-visits)[ymigval/laravel-model-cache

Laravel package for caching Eloquent model queries

7636.6k2](/packages/ymigval-laravel-model-cache)[byerikas/cache-tags

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

1412.0k](/packages/byerikas-cache-tags)[omaralalwi/lexi-translate

Laravel translation package with morph relationships and caching.

733.2k2](/packages/omaralalwi-lexi-translate)[juampi92/laravel-query-cache

Provide easy interface for caching laravel queries

2517.2k](/packages/juampi92-laravel-query-cache)[michele-angioni/support

Support is a Laravel package which promotes the use of best practices and design patterns.

181.4k1](/packages/michele-angioni-support)

PHPackages © 2026

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