hi todd !

pseudocode is great. thx. i am considering to
try both ways mentioned.

thankfully i found this forum.
it is pretty hard to find design patterns for
memcache as they are used individually in
practice.

thx joseph, boris and todd !
you guys helped me alot.


dan

On 16 Sep., 22:51, Todd Lipcon <[EMAIL PROTECTED]> wrote:
> On Tue, 16 Sep 2008, dantro wrote:
> > thanks for your reply! That means I should store all comment ids
> > as array in one key ?
>
> "should" is a matter of opinion and the specific task at hand :)
>
> > example: forum_id:100 => 1,2,3,4,5,6,7,8,9 etc.
>
> > after retrieving these ids from the main key should I query them
> > via mysql or should I have all single comments as memcache value ?
>
> Yes, though it's not a "one or the other" choice. Basically you'd end up
> with code like this:
>
> $postIds = mcget("forum_id:100");
> $postIdsOnPage = array_slice($postIds, $pageNum, $numPerPage);
> $mckeys = "post:" . $id for $id in $postIdsOnPage;
> $posts = mcget($mckeys);
> $postIdsNotInCache = figure out which ones you didn't get a hit on
> $postsFromDb = dbget($thoseIds)
> $posts = array_merge($posts, $postsFromDb);
>
> the total impact is 1 get for the ids, 1 multiget for possible hits, and 1
> SQL query with an IN condition. In a primed cache mysql isn't involved.
>
> Obviously this is pseudocode and there is plenty of abstraction you should
> be doing. We hide all of this behind a single call "dbPost::multiget($ids)"
>
> -Todd

Reply via email to