Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rg83's avatar
Level 4

Is it bad to access cache too much?

I'm working on a site where I need to check if a user has access to content on the screen. I created a method on my user model that will return me the result but it hits the db. I cache the result. On this page i need to check several times if the user has access to the content. My question is, is it ok if i access my cache multiple times or is it better for me to store the result in a variable and use that variable to see if the user has access?

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

I would create a variable, either from the DB result, or from the Cache value. It depends what you use for Cache as driver, but it will be more expensive than storing it in memory as long as it is used in one request.

Please or to participate in this conversation.