Created
July 24, 2013 02:02
-
-
Save thoslin/6067591 to your computer and use it in GitHub Desktop.
add_post_render_callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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