Laracon 2024 baby is born: Warmable, a cache warmer for Laravel #50141
Unanswered
henzeb
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Almost two weeks ago, @timacdonald had his talk. He showed us a technique where you 'warm up' the cache using a cron job and a simple invokable class. He was hoping someone would build something that would make this a whole lot easier.
Well, here it is.
https://packagist.org/packages/henzeb/warmable-laravel
Out of the box, it is a queueable Job. So when a default is set, it will dispatch itself as a job when the cache entry is missing. And this way scheduling it will be just like any other job. This also means you can do everything with it that you can do with a regular job. so if you want middleware, go ahead. If you want to retry, go ahead. Change connection or queue,? go ahead!
It also comes with events which you can also customize. So if you want a realtime app using Livewire/Volt/Reverb, you can build one.
Below an example of a few of its features:
And in your routes file it's something like:
There is a vanilla warmable as well for users that do not use Laravel, or wish to use it in other projects. It is implementing the
PSR-16 cache interface, so you can use every caching mechanism you can think of, and if not, one can implement a wrapper, and you still can use every caching mechanism you can think of.
https://packagist.org/packages/henzeb/warmable
I hope everything is documented well, not my favorite part of developing something new. Any suggestions to make it better are welcome.
Beta Was this translation helpful? Give feedback.
All reactions