Not a problem.
I love memcache because its so flexible and there are so many ways to
do the same thing. Picking the best way can be tough, best
recommendation I can give would be to try a few different ways and
load test it :D
On Sep 16, 2008, at 2:00 PM, dantro wrote:
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