views:

17

answers:

1

I'd like to build a "feed" for recent activity related to a specific section of my site. I haven't used memcache before, but I'm thinking of something like this:

  1. When a new piece of information is submitted to the site, assign a unique key to it and also add it to memcache.
  2. Add this key to the end of an existing list in memcache, so it can later be referenced.
  3. When retrieving, first retrieve the list of keys from memcache
  4. For each key retrieved, retrieve the individual piece of information
  5. String the pieces together and return them as the "feed"

E.g., user comments: user writes, "Nice idea"

  1. Assign a unique key to "Nice idea," let's say key "1234"
  2. Insert a key/data pair into memcache, 1234 -> "Nice Idea"
  3. Append "1234" to an existing list of keys: key_list -> {2341,41234,124,341,1234}
  4. Now when retrieving, first query the key list: {2341,41234,124,341,1234}
  5. For each key in the key list, retrieve the data: 2341 -> "Yes" 41234 -> "Good point" 124 -> "That's funny" 341 -> "I don't agree" 1234 -> "Nice Idea"

Is this a good approach?

Thanks!

A: 

If the list of keys is bounded in size then it should be ok. memcache by default has a 1MB item size limit.

Sounds like memcache is the only storage for the data, is it a good idea?

phsiao