DISQUS

DISQUS Hello! benjamingolub.com is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Google App Engine + Memcached + FF To Go = Bliss

Started by Benjamin Golub · 1 year ago

Google App Engine gained support for memcached today, a very high performance caching system, and I’m already using it in FF To Go.

I’ll share some code with you so you know how it works.  This is the code that renders the public feed:

def public(request):

f = friendfeed.FriendFeed()

try:

[...] ... Continue reading »

4 comments

  • I think you might be better off caching the entire response, as then subsequent requests don't even have to go through the template system, context processors, etc.

    For example:

    ...
    key = 'public_%i_%i_%s' % (num, start, service)
    response = memcache.get(key)
    if not response:
    try:
    data = f.fetch_public_feed(num=num, start=start, service=service)
    except Exception, e:
    return HttpResponseRedirect('/%s/' % e)
    extra_context = {
    'entries': data['entries'],
    ‘next’: start + num,
    }
    if start > 0:
    extra_context['has_previous'] = True
    extra_context['previous'] = start - num
    response = render_to_response(’public.html’, extra_context, context_instance=RequestContext(request))
    memcache.set(key, response, CACHE_TIME)
    return response
  • Sorry, Disqus is not so great for code snippets :(
  • It's a little trickier than that; because the user can also set the font size and the header contains a link to the user's friendfeed page. But yes; this is exactly what I do on RSSmeme (and as I'm sure you are aware it's how the Django cache middleware works). I cache the entire response (I also cache the results from the DB so hitting the html and then the API for the same data doesn't result in 2 DB requests). Since this runs on Google App Engine and the CPU is not a bottleneck at all I'm not worried about the time spent on the template system too much.

    But thanks!
  • Ahh I see--foot, meet mouth :) Still, it's cool stuff.

Add New Comment

Returning? Login