tags:

views:

41

answers:

2

Hello,

Lets suppose that we have some kind of items and these items could be rated by users. Should I store item rating and item data in different memcache keys?

Logically, we should keep rating out of main item data, because item data changes very rarely, but rating changes more often. When somebody rates the item I should invalidate only item rating key, but not whole item.

Why I'm asking this question? For example, I have 100 items per page....

  1. I'm getting item ids for this page = 1 memcache "query"
  2. I'm getting item data for each item id on page = 100 memcache "queries"
  3. I'm getting item rating for each item id on page = 100 memcache "queries"

Total : 201 memcache "queries"

Storing item rating together with main item data in one key we will get only 101 memcache "queries".

So, what is the best practice? I'm really worried about number of memcache "queries" per page. Or I shouldn't worry about it?

Thank you.

A: 

Memcache allows to put array of keys to get() method.

(Russia language) http://highload.com.ua/index.php/2009/08/05/memcache-multi-get-%D0%B7%D0%B0%D1%87%D0%B5%D0%BC/

Fetched 15000 objects with standard get in 0.47441411018372s - using get
Fetched 15000 objects with multiple get in 0.023789882659912s - using multi get
Kirzilla
A: 

If you will save item rating separately you will be unable to do the sorting by it. It is better to use mysql innodb table (if you really need to sort by rating) for that purpose (which is optimized to work with high concurrency and great write-load)

Everyz