Eloquent Query Cache
Github Repo
3.x
3.x
  • ⚡Introduction
  • 🎉Support
  • Getting Started
    • 🚀Installation
    • 🙌Showcase
  • Caching
    • ⚡Query Caching
    • 👥Relationships Caching
    • 📑Cache Tags
    • 🛑Cache Invalidation
      • 🌍Global Cache Invalidation
      • 🍸Automatic Invalidation
      • 🤔Many-to-Many Automatic Cache Invalidation
  • Advanced
    • ✨Implement Caching
      • 🔑Generating your own key
      • 🎇Implementing cache for other functions than get()
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Advanced

Implement Caching

Since this package modifies the newBaseQueryBuilder() in the model, having multiple traits that modify this function will lead to overlap.

This can happen in case you are creating your own Builder class for another database driver or simply to ease out your app query builder for more flexibility.

To solve this, all you have to do is to add the \Rennokki\QueryCache\Traits\QueryCacheModule trait and the \Rennokki\QueryCache\Contracts\QueryCacheModuleInterface interface to your Builder class.

use Rennokki\QueryCache\Traits\QueryCacheModule;
use Illuminate\Database\Query\Builder as BaseBuilder; // the base laravel builder
use Rennokki\QueryCache\Contracts\QueryCacheModuleInterface;

class MyCustomBuilder implements QueryCacheModuleInterface
{
    use QueryCacheModule;

    // the rest of the logic here.
}
trait MyBuilderTrait
{
    protected function newBaseQueryBuilder()
    {
        return new MyCustomBuilder(
            //
        );
    }
}

Make sure that the model will no longer use the original QueryCacheable trait and use the custom one instead:

class CustomModel extends Model
{
    use MyBuilderTrait;
}

CustomModel::cacheFor(30)->customGetMethod();

PreviousMany-to-Many Automatic Cache InvalidationNextGenerating your own key

Last updated 3 years ago

Was this helpful?

✨