Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
drupal does a lot of caching, have you tried looking into how it stores cache? –  karthik May 30 '12 at 14:23
    
nah! I am into MediWiki and all they do use is Memcache and in-DB cache –  nischayn22 May 30 '12 at 16:16

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Could you explain the last paragraph? I didn't get anything about it –  nischayn22 May 30 '12 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? –  dead May 30 '12 at 14:49
    
ah,No.Sounds too complex ideas for me –  nischayn22 May 30 '12 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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