Search⌘ K

Cache and Rule

Learn how to apply caching to slow-changing restaurant menu item data in Laravel APIs. Discover when to cache, how to set cache keys, invalidate cache after updates, and integrate tests to maintain data accuracy and improve performance.

Why and when to cache?

There are many ways to maintain the speed and performance of our API endpoints: Improved DB queries, DB indexes, queueing delayable actions, caching data, etc. In this lesson, we will cover caching.

We cache the data that does not frequently change. Ideally, there should be a pre-defined boundary of the data that we wish to cache. This allows us to set proper cache keys and quickly identify the places in the code where we need to invalidate the cache. Time to try it with the actual example from our API endpoints.

Menu items of ...