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. Caching
  2. Cache Invalidation

Global Cache Invalidation

Each model that uses the query caching trait has an array attached that's called getCacheBaseTags(). This is useful to attach whenever we want to flush all queries for a specific model, without passing tags.

By default, the cache base tags array contains only one element, and it's the class name (as string). This way, Eloquent Query Cache will attach the tags on any query and whenever you want to flush all queries' caches (without flushing the entire caching storage), consider using this method:

class User extends Model
{
    use QueryCacheable;

    /**
     * Set the base cache tags that will be present
     * on all queries.
     *
     * @return array
     */
    protected function getCacheBaseTags(): array
    {
        return [
            'custom_user_tag',
        ];
    }
}

From now, each query made from the User model will contain a tag called custom_user_tag and the package will know what to flush:

User::flushQueryCache();
PreviousCache InvalidationNextAutomatic Invalidation

Last updated 3 years ago

Was this helpful?

🛑
🌍