PHP MySQL – How to Store Cache Effectively

cachingMySQLPHP

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

data[301]={
        "pid"=>301,
        "friends"=>array(),
        "relatives"=>array(),
        "interests"=>array()
        }

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?

Best Answer

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.

Related Topic