from django.core.cache import cache
cached = cache.get('temp_entries')
if cached:
    result = cached
else:
    result = Temp_entry.objects.filter(sensor=49).order_by('dateTime').reverse(
        ).values_list()[:300]
cache.set('temp_entries', result, 60 * 20)
Improving performance of django DB query