1

I have a django weather site for a small local community that features view decorator caching. Currently the cache is set to expire every 5 minutes at which point the next person to hit the view will be forced to wait about 10 seconds for the view to pull data from multiple web-services.

@cache_page(60 * 5) # cache for 5 minutes  
def weather(request):  
    # lot of calls to external sites 

I'd like to set up a cron job to run the view in order to refresh the cache, once the view has run it will replace the data in the old cache. Ideally I'd like users who hit the view during the time that the new view is loading to simply get the old cached data so that they see no additional load time.

I'm sure there is an elegant way to do this with the django cache framework.

Dennis Kriechel
  • 3,719
  • 14
  • 40
  • 62
John Evans
  • 383
  • 3
  • 10

1 Answers1

2

You could try to use queryset caching similar to what johnny-cache does and expire the querysets once new data comes in rather than every n minutes.

chaos
  • 480
  • 3
  • 8
  • I found this from your key words "queryset caching": http://stackoverflow.com/questions/4631865/caching-query-results-in-django I would upvote you but I don't have 15 reputation yet... Working on it, I'll get back to you later. – John Evans May 23 '15 at 12:51