PHPackages                             mostafaznv/laracache - 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. [Database &amp; ORM](/categories/database)
4. /
5. mostafaznv/laracache

ActiveLibrary[Database &amp; ORM](/categories/database)

mostafaznv/laracache
====================

LaraCache is a customizable cache trait to cache queries on model's events

3.0.0(5mo ago)27246.8k↓24.7%7[1 PRs](https://github.com/mostafaznv/laracache/pulls)1MITPHPPHP ^8.3CI passing

Since Jun 5Pushed 5mo ago3 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (20)Used By (1)

LaraCache
=========

[](#laracache)

[![GitHub Workflow Status](https://camo.githubusercontent.com/ed0041f9bcf4b2f0369ce76af505f234c2dcef6da496eb571224e893cb53d702/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f73746166617a6e762f6c61726163616368652f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d4275696c64267374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/mostafaznv/laracache/actions)[![Codecov branch](https://camo.githubusercontent.com/903efd39b055f34afa003dd2d3f6ef1516ce7e7a59c55e559c2a1d38b95aa851/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6d6f73746166617a6e762f6c61726163616368652f6d61737465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f6465636f76)](https://app.codecov.io/gh/mostafaznv/laracache)[![Quality Score](https://camo.githubusercontent.com/7076a71ad82b7370e1048def7a5729fe0cffd425ec89b9f79a71f82fb3026560/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d6f73746166617a6e762f6c61726163616368652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/mostafaznv/laracache)[![GitHub license](https://camo.githubusercontent.com/3f25610c6781529fb1309e0fc1f707c2e6e23a791b7c08092a422adc57ae3a2d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6f73746166617a6e762f6c61726163616368653f7374796c653d666c61742d737175617265)](https://github.com/mostafaznv/laracache/blob/master/LICENSE)[![Packagist Downloads](https://camo.githubusercontent.com/0070d85705267a23adf38268c4f8ae2a8505c1ff08e16ec1fd199affae0bbc43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f73746166617a6e762f6c61726163616368653f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374)](https://packagist.org/packages/mostafaznv/laracache)[![Latest Version on Packagist](https://camo.githubusercontent.com/162a3feca7e1236a6391858cea9d30f9b9c471bc5f884ba68735dc80a800da87/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f73746166617a6e762f6c61726163616368652e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f6d706f736572)](https://packagist.org/packages/mostafaznv/laracache)

[![laracache](https://private-user-images.githubusercontent.com/7619687/244869792-13e909ba-2899-4922-a98b-f727ea26d564.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ2NTUzOTcsIm5iZiI6MTc3NDY1NTA5NywicGF0aCI6Ii83NjE5Njg3LzI0NDg2OTc5Mi0xM2U5MDliYS0yODk5LTQ5MjItYTk4Yi1mNzI3ZWEyNmQ1NjQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDMyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAzMjdUMjM0NDU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2EyMDg5ZGRhYjAwNGYwYWI3MTA5ODFiMTFjMDk3MjkxZTk4Y2UwZjUxNjIzNmZkMGJkZGU5Njk2MjJlNDY3MCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.PFvgISLaUodcWl9UpcU67SXWwgPQUUvEmfvmCN3RkT4)](https://private-user-images.githubusercontent.com/7619687/244869792-13e909ba-2899-4922-a98b-f727ea26d564.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ2NTUzOTcsIm5iZiI6MTc3NDY1NTA5NywicGF0aCI6Ii83NjE5Njg3LzI0NDg2OTc5Mi0xM2U5MDliYS0yODk5LTQ5MjItYTk4Yi1mNzI3ZWEyNmQ1NjQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDMyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAzMjdUMjM0NDU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2EyMDg5ZGRhYjAwNGYwYWI3MTA5ODFiMTFjMDk3MjkxZTk4Y2UwZjUxNjIzNmZkMGJkZGU5Njk2MjJlNDY3MCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.PFvgISLaUodcWl9UpcU67SXWwgPQUUvEmfvmCN3RkT4)

Using this package, you can cache your heavy and most used queries.

All you have to do is to define the `CacheEntity` objects in the model and specify a valid name and ttl for them.

LaraCache will handle the rest of process automatically. It will create and update cache entities based on ttl that you've defined for each entity.

Manually updating the cache entities of models after dispatching model events (creating, updating and deleting) isn't required, LaraCache manages them in the background and ensures the most up-to-date version of each cache entity.

In addition to the core LaraCache package, I have developed a complementary package called [Nova LaraCache](https://github.com/mostafaznv/nova-laracache). Nova LaraCache seamlessly integrates LaraCache with [Laravel Nova](https://nova.laravel.com), the administration panel for Laravel applications. It offers a user-friendly interface within the Laravel Nova administration panel, enabling users to conveniently moderate and manage cache entities.

---

I am on an open-source journey 🚀, and I wish I could solely focus on my development path without worrying about my financial situation. However, as life is not perfect, I have to consider other factors.

Therefore, if you decide to use my packages, please kindly consider making a donation. Any amount, no matter how small, goes a long way and is greatly appreciated. 🍺

[![Donate](https://camo.githubusercontent.com/0b7607d470e0ccaa24269275d40233442275a42b0a714b4875bccf62f6ed5295/68747470733a2f2f6d6f73746166617a6e762e6769746875622e696f2f646f6e6174652f646f6e6174652e737667)](https://mostafaznv.github.io/donate)

---

Requirements:
-------------

[](#requirements)

- PHP 8.3 or higher
- Laravel 12 or higher

To install LaraCache on older Laravel/PHP versions, consult the compatibility table below to determine which LaraCache release to use:

Laravel VersionPHP VersionLaraCache Version8.40.0 — 12.x8.0.2 — 8.5[2.5.2](https://github.com/mostafaznv/laracache/tree/2.5.2)12.x8.3 or highermaster (3.x)Installation
------------

[](#installation)

1. ##### Install the package via composer:

    [](#install-the-package-via-composer)

    ```
    composer require mostafaznv/laracache
    ```
2. ##### Publish config file:

    [](#publish-config-file)

    ```
    php artisan vendor:publish --provider="Mostafaznv\LaraCache\LaraCacheServiceProvider"
    ```
3. ##### Done

    [](#done)

Usage
-----

[](#usage)

1. ##### Add LaraCache trait to the model

    [](#add-laracache-trait-to-the-model)

    ```
