All Projects → spiritix → Lada Cache

spiritix / Lada Cache

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

Projects that are alternatives of or similar to Lada Cache

Laravel Eloquent Query Cache
Adding cache on your Laravel Eloquent queries' results is now a breeze.
Stars: ✭ 529 (+24.76%)
Mutual labels:  eloquent, database, redis, cache, laravel
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (-43.87%)
Mutual labels:  eloquent, database, laravel, laravel-5-package
Laravel Tags
Add tags and taggable behaviour to your Laravel app
Stars: ✭ 1,026 (+141.98%)
Mutual labels:  eloquent, database, laravel
Watchable
Enable users to watch various models in your application.
Stars: ✭ 65 (-84.67%)
Mutual labels:  eloquent, laravel, laravel-5-package
Laravel Cacheable
Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.
Stars: ✭ 107 (-74.76%)
Mutual labels:  eloquent, cache, laravel
Rememberable
Query caching for Laravel
Stars: ✭ 960 (+126.42%)
Mutual labels:  eloquent, caching, laravel
Freelancers Market
Laravel Project to help freelance websites clients and freelancers to find each other.
Stars: ✭ 39 (-90.8%)
Mutual labels:  eloquent, redis, laravel
Laravel Settings
Store key value pair in database as settings
Stars: ✭ 107 (-74.76%)
Mutual labels:  eloquent, database, laravel
Simple Cache
An easy to use Caching trait for Laravel's Eloquent Models.
Stars: ✭ 19 (-95.52%)
Mutual labels:  eloquent, cache, laravel
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (-53.3%)
Mutual labels:  eloquent, laravel, laravel-5-package
Stackexchange.redis.extensions
Stars: ✭ 419 (-1.18%)
Mutual labels:  redis, cache, caching
Gorose
GoRose(go orm), a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developer and python or ruby developer. Currently provides six major database drivers: mysql,sqlite3,postgres,oracle,mssql, Clickhouse.
Stars: ✭ 947 (+123.35%)
Mutual labels:  eloquent, database, laravel
Eloquent Driver
A package that allows you to store Statamic entries in a database.
Stars: ✭ 28 (-93.4%)
Mutual labels:  eloquent, database, laravel
Elasticsearch
The missing elasticsearch ORM for Laravel, Lumen and Native php applications
Stars: ✭ 375 (-11.56%)
Mutual labels:  eloquent, caching, laravel
Improved Polymorphic Eloquent Builder
🔨 Improved Polymorphic Eloquent Builder
Stars: ✭ 12 (-97.17%)
Mutual labels:  eloquent, laravel, laravel-5-package
Laravel Optimistic Locking
Adds optimistic locking feature to eloquent models.
Stars: ✭ 71 (-83.25%)
Mutual labels:  eloquent, database, laravel
Scrapbook
PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.
Stars: ✭ 279 (-34.2%)
Mutual labels:  redis, cache, caching
Laravel Repositories
[ABANDONED] Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
Stars: ✭ 664 (+56.6%)
Mutual labels:  eloquent, cache, laravel
Laravel
Laravel Model Generator
Stars: ✭ 715 (+68.63%)
Mutual labels:  eloquent, database, laravel
Laravel Migrate Fresh
An artisan command to build up a database from scratch
Stars: ✭ 179 (-57.78%)
Mutual labels:  eloquent, database, laravel

Lada Cache

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

Build Status Code Climate Total Downloads Latest Stable Version Latest Unstable Version License

Contributors wanted! Have a look at the open issues and send me an email if you are interested in a quick introduction via Hangouts.

Table of Contents

For further information on how this library works and how to debug it please have a look at the Wiki.

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 (supports clustering)

Version Compatibility

Laravel PHP Lada Cache
5.1-5.6 5.6.4+ 2.x
5.7-5.8 7.1+ 3.x
6.x 7.2+ 4.x
7.x 7.2+ 5.x
8.x 7.3+ 5.x

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?

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:

  • 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?

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:

  • 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

Installation

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

The Lada Cache service provider will automatically be installed using 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

Use the following command to publish the lada-cache.phpconfig file to your configuration folder:

php artisan vendor:publish 

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

  • Doesn't work with raw SQL 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 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.

Contributing

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

  • Coding standard - It's PSR-2
  • 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

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].