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

Cache Tags

Some caching stores accept tags. This is really useful if you plan on tagging your cached queries and invalidate only some of the queries when needed.

In fact, this is the recommended way of caching your queries because it will be much easier to invalidate them later, even in such complex situations where, for example, you will be handling a lot of queries, like queries for listing, retrieving by ID and eventually invalidating the listing cache upon a new record, updated record or deleted record.

The following example states queries that retrieve books based on their shelf_id. The books from shelf 1 will be invalidated, and the books from shelf 2 will be not.

$shelfOneBooks = Book::where('shelf_id', 1)
    ->cacheTags(['shelf:1'])
    ->get();

$shelfTwoBooks = Book::where('shelf_id', 2)
    ->cacheTags(['shelf:2'])
    ->get();
PreviousRelationships CachingNextCache Invalidation

Last updated 3 years ago

Was this helpful?

📑