The data in my website is stored in many different tables(friends,relatives,etc) and every-time I have to query each and every table. But all this data is subject centric. E.g. data for a person is of the form


So I want to store it in a cache in the db (and hence query only one table). But how do I store such data? should I be using blobs?

  • drupal does a lot of caching, have you tried looking into how it stores cache?
    – karth
    Commented May 30, 2012 at 14:23
  • nah! I am into MediWiki and all they do use is Memcache and in-DB cache
    – nischayn22
    Commented May 30, 2012 at 16:16

2 Answers 2


I don't suggest you to use another table as a cache.

If you want to cache data, It's more appropriate use a technology like memcached (http://memcached.org/). This specialized storage should operate near your data access layer.

In addition I'll use a IoC/DI framework to integrate the code devoted to manage caching into the existing data layer. In this way the code used to manipulate data should not change at all.

  • Could you explain the last paragraph? I didn't get anything about it
    – nischayn22
    Commented May 30, 2012 at 14:30
  • Yes, without problems. It's a design question about decoupling the code you would add for manage the cache from the existing data layer code. The acronyms stands for Inversion Of Control (it.wikipedia.org/wiki/Inversion_of_Control) and Dependency Injection (it.wikipedia.org/wiki/Dependency_injection). Regardless of the language you use, you can find various libraries that implement these patterns. Need further explanation?
    – gsscoder
    Commented May 30, 2012 at 14:49
  • ah,No.Sounds too complex ideas for me
    – nischayn22
    Commented May 30, 2012 at 16:42

You could store is in any serialized form, json or PHP serialize() when you are using PHP.

I think you always need the whole blob of data when reading and using the cache so it does not care if you store it this way. Also it is fast accessible when you have a good primary key.

You could also consider using memcache which stores it in memory and autoexpires the cache if needed. It uses the same key / value solution.

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.