Skip to content

Duplicated Queries #16329

Closed Answered by brandonkelly
yannkost asked this question in Ideas
Dec 13, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Caching is tricky. Too much caching can have a net negative impact on performance, and leads to bugs if the cache isn’t getting invalidated when it should. Caching every database query would certainly result in both of those.

Element queries do provide a cache() method though, which can be used to opt into caching them on a per-query basis. It automatically sets a tag dependency on the cache that ensures it will get cleared whenever something in the results may have changed.

Your first goal should be to reduce the number of queries that are getting executed in the first place, regardless of whether they’re cached, using eager-loading. Craft 5 makes that a lot easier thanks to lazy eager-l…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@brandonkelly
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants