PHPackages                             dialloibrahima/smart-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. dialloibrahima/smart-cache

ActiveLibrary[Caching](/categories/caching)

dialloibrahima/smart-cache
==========================

Smart caching utilities for Laravel applications

v2.3.0(1mo ago)17125MITPHPPHP ^8.3CI passing

Since Dec 10Pushed 1mo agoCompare

[ Source](https://github.com/ibra379/smart-cache)[ Packagist](https://packagist.org/packages/dialloibrahima/smart-cache)[ Docs](https://github.com/ibra379/smart-cache)[ RSS](/packages/dialloibrahima-smart-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (26)Versions (14)Used By (0)

🚀 Laravel SmartCache
====================

[](#-laravel-smartcache)

[![Latest Version on Packagist](https://camo.githubusercontent.com/dcc3428b756c9c9c829540c9387f4d76a534506cc3eec5714287d98983893f29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6469616c6c6f6962726168696d612f736d6172742d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dialloibrahima/smart-cache)[![GitHub Tests Action Status](https://camo.githubusercontent.com/7640707a85f6676157f3f953e01d0a269e30aebcf1b027745244528257b22a64/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f696272613337392f736d6172742d63616368652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ibra379/smart-cache/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/d42ed2c06cb1da218a17648bd125395d5101f19d246916adb7ac5ace17aeabd1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6469616c6c6f6962726168696d612f736d6172742d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dialloibrahima/smart-cache)[![PHP Version](https://camo.githubusercontent.com/a35cf67061a49f871c2eb2a793164bc1d19a4b8bb62c92ea4c4f0334155df9c2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://www.php.net/)[![Laravel Version](https://camo.githubusercontent.com/b6c6fc0ff2b3f9f6ce91d9df8adb8719bd12e8f9b593c36584e76e2a5eabd293/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31302e7825323025374325323031312e7825323025374325323031322e782d4646324432302e7376673f7374796c653d666c61742d737175617265)](https://laravel.com/)

**SmartCache** adds automatic and intelligent caching to Eloquent queries, with automatic invalidation when data changes. **Zero configuration, maximum performance.**

---

🆕 What's New in v2.2
--------------------

[](#-whats-new-in-v22)

FeatureDescription🔗 **Cache Relations Diagram**Mermaid diagram showing invalidation relationships🔄 **Cascade Invalidation**Dashboard invalidation cascades to related models🛠️ **Fixed Clear All**Now properly clears all model caches✅ **63 Tests**124 assertions for robust reliability```
composer require dialloibrahima/smart-cache:^2.2
```

---

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [The Problem](#-the-problem)
- [The Solution](#-the-solution)
- [Installation](#-installation)
- [Quick Start](#-quick-start)
- [How It Works](#-how-it-works)
- [API Reference](#-api-reference)
- [Web Dashboard](#-web-dashboard)
- [Artisan Commands](#-artisan-commands)
- [Configuration](#%EF%B8%8F-configuration)
- [Use Cases](#-use-cases)
- [Best Practices](#-best-practices)
- [Testing](#-testing)
- [Requirements](#-requirements)
- [Roadmap](#-roadmap)
- [Comparison with Alternatives](#-comparison-with-alternatives)
- [Contributing](#-contributing)
- [License](#-license)

---

😰 The Problem
-------------

[](#-the-problem)

Manually managing Eloquent query caching is tedious and error-prone:

```
// ❌ BEFORE: Manual cache everywhere
$users = Cache::remember('active_users', 3600, function () {
    return User::where('active', true)->get();
});

// And remember to invalidate... always!
User::created(function ($user) {
    Cache::forget('active_users');  // 😱 Easy to forget!
});

User::updated(function ($user) {
    Cache::forget('active_users');  // 😱 You have to do this for every event!
});

User::deleted(function ($user) {
    Cache::forget('active_users');  // 😱 And for every query!
});
```

### Common Problems:

[](#common-problems)

ProblemImpact🔄 Manual cache everywhereDuplicated and verbose code🧠 Easy to forget invalidationStale (old) data shown to users🐛 Hardcoded cache keysCollisions and hard-to-debug bugs📊 No centralized managementImpossible to monitor cache hits/misses---

✨ The Solution
--------------

[](#-the-solution)

With **SmartCache**, everything becomes automatic:

```
// ✅ AFTER: One line, everything handled automatically
$users = User::smartCache()->where('active', true)->smartGet();

// ✅ Automatically cached with a unique key based on the query
// ✅ Invalidated when User is created/updated/deleted
// ✅ Zero configuration needed
```

---

📦 Installation
--------------

[](#-installation)

```
composer require dialloibrahima/smart-cache
```

Publish the configuration file (optional):

```
php artisan vendor:publish --tag="smart-cache-config"
```

---

⚡ Quick Start
-------------

[](#-quick-start)

### 1. Add the Trait to Your Model

[](#1-add-the-trait-to-your-model)

```
