tags:

views:

102

answers:

2

Hi. I'm using memcache to design a cache for the model layer of a web application, one of my biggest problems is data consistency. It came to my mind caching data like this: (key=query, value=list of object ids result of the query) for each id of the list: (key=object.id, value=object)

So, every time a query is done: If the query already exists I retrieve the objects signaled in the list from the cache. If it doesn't, all the objects of the lists are stored in the cache replacing any other old value.

Has someone use this alternative, is it god? any other ideas?

A: 

Welcome to the world of concurrency programming. You'll want to learn a bit about mutual exclusion. If you tell us what language/platform you are developing for we can describe more specifically your options.

Stu Thompson
+1  A: 

Caching is one of those topics where there is no one right answer - it depends on your domain.

The caching policy that you describe may be sufficient for your domain. However, you don't appear to be worried about stale data. Often I would expect to see a timestamp against some of the entities - if the cached value is older than some system defined parameter, then it would be considered stale and re-fetched.

For more discussion on caching algorithms, see Wikipedia (for starters)

Seb Rose