Skip to content

Instantly share code, notes, and snippets.

@thoslin
Created July 24, 2013 02:02
Show Gist options
  • Save thoslin/6067591 to your computer and use it in GitHub Desktop.
Save thoslin/6067591 to your computer and use it in GitHub Desktop.
add_post_render_callback
if timeout:
cache_key = learn_cache_key(request, response, timeout, self.key_prefix, cache=self.cache)
# Ensure the template is literally rendered. Cause if you are using TemplateResponse. The rendering doesn't happen
# Until it reach the bottom of response middleware
# Actually it happens in django wsgi handler which lives at django/core/handlers/base.py
if hasattr(response, 'render') and callable(response.render):
response.add_post_render_callback(
lambda r: self.cache.set(cache_key, r, timeout)
)
else:
self.cache.set(cache_key, response, timeout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment