1

If I want to use Query Caching as in the tutorial here :

Yii Query Caching Guide

whether I should have a update_time field in every table?

$dependency = new CDbCacheDependency('SELECT MAX(update_time) FROM tbl_post');

Is the field must exist to be able to use the query cache?

2 Answers 2

2

The guide only gives you an example, how you can use a cache dependency with query caching, but a dependency is not mandatory. If you use one, you can come up with your own SQL to find out, if the cached content is still valid. So the update_time field is also not mandatory.

Sign up to request clarification or add additional context in comments.

Comments

0

to answer your question, as Michael has already written, it's not mandatory. To Know more about this, You should understand the role played by the dependency query.

Consider an example. You want to cache the query which will list all the users. Something like SELECT * FROM users. Assume that at any point of time, it is 100 users.

Now the main question is when do you think your cached data becomes invalid? Whenever the new user is added, you need to re-query (Not to use Cached Data/Invalidate Cache Data). How to find that new user is added? By Querying the ID Number. So if the query SELECT MAX(ID) FROM Users returns different value then it means the new user was added.

Remember If the user is deleted, then my example will not be valid. That time, after deleting the user, you should delete the Respective Cache Data.

In this way, you should find out the relevant Queries which can be used to Validate the Cache Data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.