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.
- Full-Stack Developer
Nu Image Medical
- Senior Software Developer
Remote (US ONLY)/Kenilworth, NJ
- Senior Back-end Laravel API Developer - Immediate Contract (Full Time)
ApproveMe // Document Signing
- Web Development Project Manager
- Experienced Laravel/VueJS Developer (Freelance)
Remote (preferably in the US)
- Senior React / Laravel Developer
The C.A.S.E. Engineering Group
- Software Engineer