Laravel Tagged Cache is a reasonably straightforward wrapper around the cache implementation to reduce complexity regarding caching in your Models. Note that this requires using a Cache implementation that supports tags.

':displayname) or anything like that, as the heavy lifting is done inside the cache tags instead.

If, for example, you put something like this in your BlogEntry model: public function getContent(): string { return $this->taggedCache('markdown')->remember('content', now()->addHour(), fn () => $this->entry)}

Something like this in your BlogEntryObserver would do the trick: public function updated(BlogEntry $blogEntry): void { if ($blogEntry->isDirty(['title', 'content'])) { $blogEntry->taggedCache()->flush(); }}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners