I want to know, when all the cache tables are stored in database, then whats the logic behind keeping any data to cache, because whenever we query cache, it again hits the database, same as other normal tables exists in database do.

How cache tables are different from other normal tables in database? How cache boost performance when all cache tables also exists in database?


2 Answers 2


Cache tables contain the results of expensive queries. Often more than one query in a single cache row.

As a contrived example, take a node. When you load a node, you have to join in all of the single field tables containing it's data, plus make a bunch of separate queries for extra data. That's a lot of db load.

Wouldn't it be quicker if you could make just one, single, light query and get all of that information in one go?

That's what cache bins are for. There may well be scenarios where querying from cache is as/more expensive than the original operation, but they'd be rare.

Also don't forget your cache doesn't have to be in the database, you can get considerable improvements moving it into memory.

  • Just so you know, I swear I never saw your answer, you answered while I was typing my original answer. They are both quite similar, if you would like me to delete it, let me know since the rule for similar answers is whomever answers first.
    – No Sssweat
    Aug 25, 2016 at 14:18
  • 2
    @NoSssweat Don't sssweat it, never hurts to have the same thing explained in different words; sometimes people get a better understanding of something when it's phrased differently
    – Clive
    Aug 25, 2016 at 14:29

Here is the logic behind it. The cache tables stores/saves the results of your queries. So instead of having to run query X every single time, you store the results of query X in the cache table. So all you have to do is retrieve the results.

Instead of saving the cache to your database, you could/should if you can, store them in memory using modules such as Redis (maintained by Berdir) or Memcached which will retrieve the values much faster than using/querying the database.

Your Answer

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

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