Package Data | |
---|---|
Maintainer Username: | spiritix |
Maintainer Contact: | mi@matthias-isler.ch (Matthias Isler) |
Package Create Date: | 2015-10-12 |
Package Last Update: | 2024-06-21 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-27 15:01:49 |
Package Statistics | |
---|---|
Total Downloads: | 374,590 |
Monthly Downloads: | 7,278 |
Daily Downloads: | 277 |
Total Stars: | 538 |
Total Watchers: | 19 |
Total Forks: | 68 |
Total Open Issues: | 16 |
A Redis based, fully automated and scalable database cache layer for Laravel
For further information on how this library works and how to debug it please have a look at the Wiki.
Laravel | PHP | Lada Cache :---------|:----------|:---------- 5.1-5.6 | 5.6.4+ | 2.x 5.7 | 7.1+ | 3.x
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.
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). Unfortunately, these caching systems have some very serious limitations:
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.
As you may have discovered while looking at the source code, this library is built directly on top of Laravel Redis instead of Laravel Cache, which would make more sense from a general point of view. However, there are several important reasons behind this decision:
If you still want to use another storage backend, please feel free to contribute.
Lada Cache can be installed via Composer by requiring the
spiritix/lada-cache
package in your project's composer.json
.
Or simply run this command:
composer require spiritix/lada-cache
Now you must register the service provider when bootstrapping your Laravel application.
Find the providers
key in your config/app.php
and register the Lada Cache Service Provider.
'providers' => array(
// ...
Spiritix\LadaCache\LadaCacheServiceProvider::class,
)
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.
Use the following command to publish the lada-cache.php
config file to your configuration folder:
php artisan vendor:publish --provider="Spiritix\LadaCache\LadaCacheServiceProvider" --tag=config
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
DB::connection('foo')
. Instead, specify the protected $connection = 'foo';
property in the relevant models.id
as column name for your primary keys.Contributions in any form are welcome. Please consider the following guidelines before submitting pull requests:
Lada Cache is free software distributed under the terms of the MIT license.