Reputation: 110382
I have a template that I would like to cache for django. The url is something like this:
/cache_my_page/<object_number>/
There are about a million objects here -- so 1M pages I would like to cache. Is there a way to pre-cache all these pages, before a user loads it? Or does django not offer that, and I need to dive into something like redis or memcache to do that?
Upvotes: 1
Views: 692
Reputation: 7778
You can compile your templates outside a request-response, but that's probably not what you want. Django is for dynamic content. Though if your objects hardly ever changes you could certainly loop over your objects, dump the resulting content of the request into a static file and let it be served by nginx.
https://docs.djangoproject.com/en/1.7/ref/templates/api/#compiling-a-string
Though there are more elegant solutions for dynamic content as well. How you can avoid rerendering a url which was requested before, is described here in detail:
http://www.djangobook.com/en/2.0/chapter15.html
Or have a look at a solution like Varnish taking Django out of the equation:
Varnish is a piece of software that sits between our load balancers and our Django backends and acts as an HTTP caching layer. What this means is that it can cache the entire HTTP response without even hitting a Django server, if we know that request won’t be unique.
http://blog.disqus.com/post/62187806135/scaling-django-to-8-billion-page-views
Upvotes: 1