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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners