The Laravel Model caching is a package by Mike Bronner that adds Model caching to model queries automatically. Here are the main highlight features from the package’s readme:
- Automatic, self-invalidating relationship (both eager- and lazy-loaded) caching.
- Automatic, self-invalidating model query caching.
- Automatic use of cache tags for cache providers that support them (will flush entire cache for providers that don’t).
The readme also outlines the inspiration and reason Mike created the package in the first place:
I created this package in response to a client project that had complex, nested forms with many <select>’s that resulted in over 700 database queries on one page. I needed a package that abstracted the caching process out of the model for me, and one that would let me cache custom queries, as well as cache model relationships. This package is the attempt to address those requirements.
For the best performance, you should use a “taggable” cache provider like Redis or Memcached. With all model queries and relationships cached, you will see a nice performance boost. Your mileage will vary on performance based on your use-case.
For more information check out the GitHub repository.
Filed in: Laravel Packages
Join the weekly newsletter and never miss out on new tips, tutorials, and more.
- PHP Web Developer
Christ for all Nations
- PHP Developer
Manhattan, KS (open to Remote)
- Mid-Senior Laravel Developer
- Full Stack Web Developer
Las Vegas, NV
- Staff Software Engineer (Laravel)
- Software Engineer (PHP, Laravel, Vue)
Los Angeles, CA
- Software Engineer Level 1 / Level 2
St. Pete. / Tampa Area, FL / Remote