[Django]-Speed up often used Django random query

4👍

Django supports a variety of caching methods, both built-in and memcached. I would select one of the methods in the documentation, and create a specific view for your json response. You could then use the @cache_page decorator and specify a particular time.

from django.views.decorators.cache import cache_page

@cache_page(60 * 15)
def my_view(request):
    ...

https://docs.djangoproject.com/en/1.3/topics/cache/

0👍

If the tables are linked via foreign key, maybe using select_related? From the link, the example they give (you’ll need to scroll down a bit):

>>> e = Entry.objects.select_related().get(id=2)
>>> print e.blog  # Doesn't hit the database; uses cached version.
>>> print e.blog  # Doesn't hit the database; uses cached version.

I’m not sure about three tables, but it works well for two.

Leave a comment