10

In Model Classes, I have seen this constant, CACHE_ID and CACHE_TAG, I know it is used to store data in the cache.

But how does it actually work. What should be considered while caching and flushing our custom variables?.

12

Cache id is used to identify a specific cache record.
If you save something in the cache you can later retrieve it by its id.
Cache tags are a way to assign labels to different cache records so you can later clear multiple cache entries based on those labels (tags).

For example, let's say you want to cache a category view page.
This will have as tags category_{id of category here}.
But the category page contains products. SO maybe you want to also add the tags product_{id of each product here}.

Now, when you change a product and/or a category you need to clean the cache for each entity involved.
So when you update a product you clear all cache entries with the tag product_{id of product here}.
This way, the category page cache I mentioned above will get cleared also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.