PHPackages                             lab2view/lada-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. lab2view/lada-cache

ActiveLibrary[Caching](/categories/caching)

lab2view/lada-cache
===================

A Redis based, automated and scalable database caching layer for Laravel

03.7k↓11.3%PHP

Since May 6Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

Lada Cache [![](https://camo.githubusercontent.com/3a6d56b181377f57db905b9101ff213ba6c54feed9e7cbae6aa13ab2bc3be2db/68747470733a2f2f63646e342e69636f6e66696e6465722e636f6d2f646174612f69636f6e732f76617a323130312f3531322f666163655f312d3531322e706e67)](https://camo.githubusercontent.com/3a6d56b181377f57db905b9101ff213ba6c54feed9e7cbae6aa13ab2bc3be2db/68747470733a2f2f63646e342e69636f6e66696e6465722e636f6d2f646174612f69636f6e732f76617a323130312f3531322f666163655f312d3531322e706e67)
================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#lada-cache-)

A Redis based, fully automated and scalable database cache layer for Laravel

[![Build Status](https://camo.githubusercontent.com/ec8f1524228ead52592bac17464b618976b53908939d2f6cc5eeb29b2cfe83ec/68747470733a2f2f7472617669732d63692e6f72672f73706972697469782f6c6164612d63616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/spiritix/lada-cache)[![Code Climate](https://camo.githubusercontent.com/e4addc705774c7f3e661384c5fdb29c7840ac4a41ae6296d70e49aa4a923f392/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73706972697469782f6c6164612d63616368652f6261646765732f6770612e737667)](https://codeclimate.com/github/spiritix/lada-cache)[![Total Downloads](https://camo.githubusercontent.com/09b7cc40f71c2d222f6f932063f8de69f38c7c4ff37132cd461431cb931f31af/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f6c6164612d63616368652f642f746f74616c2e737667)](https://packagist.org/packages/spiritix/lada-cache)[![Latest Stable Version](https://camo.githubusercontent.com/10cc8354338577a63aa3ade057c9f1868549c054d09927d95f8693ea9e6ad63d/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f6c6164612d63616368652f762f737461626c652e737667)](https://packagist.org/packages/spiritix/lada-cache)[![Latest Unstable Version](https://camo.githubusercontent.com/0c4a100d260d41b8e25d20cf54c9a2b4c54cb96c8ef82767260fde84d41ffabb/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f6c6164612d63616368652f762f756e737461626c652e737667)](https://packagist.org/packages/spiritix/lada-cache)[![License](https://camo.githubusercontent.com/bde8802d690073894ec29beb162ae63c9bc577a187e5caf18f37db718f558b7e/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f6c6164612d63616368652f6c6963656e73652e737667)](https://packagist.org/packages/spiritix/lada-cache)

*Contributors wanted! Have a look at the [open issues](https://github.com/spiritix/lada-cache/issues) and send me an email if you are interested in a quick introduction via Hangouts.*

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

[](#table-of-contents)

- [Features](#features)
- [Version Compatibility](#version-compatibility)
- [Performance](#performance)
- [Why?](#why)
- [Why only Redis?](#why-only-redis)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Console commands](#console-commands)
- [Known issues and limitations](#known-issues-and-limitations)
- [Contributing](#contributing)
- [License](#license)

For further information on how this library works and how to debug it please have a look at the [Wiki](https://github.com/spiritix/lada-cache/wiki).

Features
--------

[](#features)

- Automatically caches all database queries
- Intelligent cache invalidation with high granularity
- Works with existing code, no changes required after setup
- Possibility to cache only specific models or exclude some models
- Makes use of [Laravel Redis](https://laravel.com/docs/7.x/redis) (supports [clustering](https://laravel.com/docs/7.x/redis#configuration))

Version Compatibility
---------------------

[](#version-compatibility)

LaravelPHPLada Cache5.1-5.65.6.4+2.x5.7-5.87.1+3.x6.x7.2+4.x7.x7.2+5.x8.x7.3+5.x9.x8.0+5.xPerformance
-----------

[](#performance)

The performance gain achieved by using Lada Cache varies between 5% and 95%. It heavily depends on the quantity and complexity of your queries. The more (redundant) queries per request your application fires and the more complex they are, the bigger the performance gain will be. Another important factor to consider is the amount of data returned by your queries, if a query returns 500MB of data, Lada Cache won't make it faster at all. Based on experience, the performance gain in a typical Laravel web application is around 10-30%.

Other than the performance gain, an essential reason to use Lada Cache is the reduced the load on the database servers. Depending on your infrastructure, this may result in reasonable lower cost and introduce new possibilities to scale up your application.

Why?
----

[](#why)

A lot of web applications make heavy use of the database. Especially using an ORM like Eloquent, queries repeat often and are not always very efficient. One of the most common solutions for this problem is caching the database queries.

Most RDBMS provide internal cache layers (for example [Mysql Query Cache](https://dev.mysql.com/doc/refman/5.7/en/query-cache.html)). Unfortunately, these caching systems have some very serious limitations:

- They do not cache queries over multiple tables (e.g. if the queries are using joins)
- The invalidation granularity is very low (if a single row changes, the entire table gets removed from the cache)
- They are not distributed, if you have multiple database servers the cache will be created on all of them
- They are not scalable

Laravel, on the other hand, provides the possibility to cache particular queries manually. The problem is that it doesn't invalidate the cached queries automatically, you'll need to let them expire after a certain time or invalidate them manually on all places where the affected data might be changed.

This library provides a solution for all of the mentioned problems. Install, scale up and lean back.

Why only Redis?
---------------

[](#why-only-redis)

As you may have discovered while looking at the source code, this library is built directly on top of [Laravel Redis](https://laravel.com/docs/7.x/redis) instead of [Laravel Cache](https://laravel.com/docs/7.x/cache), which would make more sense from a general point of view. However, there are several important reasons behind this decision:

- Storage must be in-memory (wouldn't make much sense otherwise)
- Storage must be easily scalable
- Storage must support tags (Laravel Cache does support tags, but the implementation is very bad and slow)

If you still want to use another storage backend, please feel free to contribute.

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

[](#requirements)

- PHP 8.0+
- Redis 2+
- Laravel 9.0+ (for older versions see [Version Compatibility](#version-compatibility))
- [PhpRedis](https://github.com/phpredis/phpredis) increases cache performance (optional but recommended)
- [Laravel Debugbar](https://github.com/barryvdh/laravel-debugbar) provides debug information (optional)

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

[](#installation)

Lada Cache can be installed via [Composer](http://getcomposer.org) by requiring the `spiritix/lada-cache` package in your project's `composer.json`. Or simply run this command:

```
composer require spiritix/lada-cache
```

The Lada Cache service provider will automatically be installed using [Package Discovery](https://laravel.com/docs/7.x/packages#package-discovery).

Finally, all your models must include the `Spiritix\LadaCache\Database\LadaCacheTrait` trait. It's a good practice to create a base model class which includes the trait and then gets extended by all your models.

```
class Car extends \Illuminate\Database\Eloquent\Model {

    use \Spiritix\LadaCache\Database\LadaCacheTrait;

    // ...
}
```

*Don't try to only have specific models including the Lada Cache trait, it will result in unexpected behavior. In the configuration, you will find the possibility to include or exclude specific models.*

Configuration
-------------

[](#configuration)

Use the following command to publish the `lada-cache.php`config file to your configuration folder:

```
php artisan vendor:publish
```

Console commands
----------------

[](#console-commands)

You may truncate the cache by running the following command:

```
php artisan lada-cache:flush
```

If you want to temporarily disable the cache (for example before running migrations), use these commands:

```
php artisan lada-cache:disable
php artisan lada-cache:enable
```

Known issues and limitations
----------------------------

[](#known-issues-and-limitations)

- Doesn't work with [raw SQL queries](https://laravel.com/docs/7.x/database#running-queries). This would require an SQL parser to be implemented which is quite hard and very inefficient. As long as you are only using raw queries for reading data, it just won't get cached. Serious issues will only occur if you use raw queries for writing data (which you shouldn't be doing anyway).
- Doesn't work with [multiple connections](https://laravel.com/docs/7.x/database#using-multiple-database-connections) if done like `DB::connection('foo')`. Instead, specify the `protected $connection = 'foo';` property in the relevant models.
- The cache must be truncated manually after migrations are executed.
- Pessimistic locking (sharedLock, lockForUpdate) requires usage of [raw SQL queries](https://github.com/spiritix/lada-cache/issues/49).
- Some third-party packages are not working well together with Lada Cache. A workaround for most of the issues can be found [here](https://github.com/spiritix/lada-cache/issues/99#issuecomment-1017250267).

Contributing
------------

[](#contributing)

Contributions in any form are welcome. Please consider the following guidelines before submitting pull requests:

- **Coding standard** - It's [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
- **Add tests!** - Your PR won't be accepted if it doesn't have tests.
- **Create feature branches** - I won't pull from your master branch.

License
-------

[](#license)

Lada Cache is free software distributed under the terms of the MIT license.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 Bus Factor1

Top contributor holds 73.4% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/99e115900c1ce7b8b670c459c421c6e57cadf20549010f96285406847aa109d5?d=identicon)[Tcharod](/maintainers/Tcharod)

---

Top Contributors

[![spiritix](https://avatars.githubusercontent.com/u/2979494?v=4)](https://github.com/spiritix "spiritix (127 commits)")[![Swanty](https://avatars.githubusercontent.com/u/7765070?v=4)](https://github.com/Swanty "Swanty (11 commits)")[![KnightAR](https://avatars.githubusercontent.com/u/195225?v=4)](https://github.com/KnightAR "KnightAR (5 commits)")[![qodeboy](https://avatars.githubusercontent.com/u/543453?v=4)](https://github.com/qodeboy "qodeboy (5 commits)")[![fridzema](https://avatars.githubusercontent.com/u/8180660?v=4)](https://github.com/fridzema "fridzema (3 commits)")[![xwiz](https://avatars.githubusercontent.com/u/3619843?v=4)](https://github.com/xwiz "xwiz (3 commits)")[![tof06](https://avatars.githubusercontent.com/u/2961054?v=4)](https://github.com/tof06 "tof06 (3 commits)")[![ethaizone](https://avatars.githubusercontent.com/u/1168777?v=4)](https://github.com/ethaizone "ethaizone (2 commits)")[![genesiscz](https://avatars.githubusercontent.com/u/1512353?v=4)](https://github.com/genesiscz "genesiscz (2 commits)")[![tcharod](https://avatars.githubusercontent.com/u/24205635?v=4)](https://github.com/tcharod "tcharod (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![diegotibi](https://avatars.githubusercontent.com/u/25210612?v=4)](https://github.com/diegotibi "diegotibi (2 commits)")[![miraries](https://avatars.githubusercontent.com/u/4648498?v=4)](https://github.com/miraries "miraries (1 commits)")[![Mehrdad-Dadkhah](https://avatars.githubusercontent.com/u/3860685?v=4)](https://github.com/Mehrdad-Dadkhah "Mehrdad-Dadkhah (1 commits)")[![MGA-Kontainer](https://avatars.githubusercontent.com/u/95886639?v=4)](https://github.com/MGA-Kontainer "MGA-Kontainer (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![odiaseo](https://avatars.githubusercontent.com/u/870628?v=4)](https://github.com/odiaseo "odiaseo (1 commits)")[![savornicesei](https://avatars.githubusercontent.com/u/917232?v=4)](https://github.com/savornicesei "savornicesei (1 commits)")

### Embed Badge

![Health badge](/badges/lab2view-lada-cache/health.svg)

```
[![Health](https://phpackages.com/badges/lab2view-lada-cache/health.svg)](https://phpackages.com/packages/lab2view-lada-cache)
```

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

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