I have got a question setup that puts 28 random records from the database right into a JSON response. This site is hit frequently, every couple of seconds, but is presently not fast enough for my liking.

Within the JSON response I've:

  • ID's
  • Usernames
  • a Base64 thumbnail

All of these originate from three linked tables.
I'd be keen to listen to of one other solutions, rather than customers simply striking a webpage, searching for 28 random records and spitting back the response. One idea I'd:

  • Possess a process running that produces a cached page every thirty seconds approximately using the JSON response.

Is the best place? If that's the case, I'd be keen to listen to how this is done.

Many thanks,
Hope everybody is well

Django supports a number of caching techniques, both built-in and memcached. I'd choose among the techniques within the documentation, and make up a specific view for the json response. You can then make use of the @cache_page decorator and specify a specific time.

from django.sights.designers.cache import cache_page

@cache_page(60 * 15)

def my_view(request):



When the tables are linked via foreign key, maybe using choose_related? In the link, the example they provide (you will need to scroll lower a little):

>>> e = Entry.objects.choose_related().get(id=2)

>>> print e.blog  # Does not hit the database uses cached version.

>>> print e.blog  # Does not hit the database uses cached version.

I am unsure around three tables, however it can be useful for two.