- July 25, 2007
- cache decorators
- 4 (after 4 ratings)
This takes advantage of a recently added feature to django, being able to give it real functions as the view instead of having it be a string that is has to look up itself.
It takes advantage of how decorators work and how
cache_control works, normally you'd do something like this:
@cache_control(private=True, public=False) def view_stuff(request): # ... return response
Which is equal to doing
view_stuff = cache_control(private=True, public=False)(view_stuff) after definition.
cache_control is a function factory, more or less, which we use to our advantage.
1 2 3 4 5 6 7 8 9 10 11
from django.views.decorators.cache import cache_control from someproj.someapp.views import foo_view # ... open_cache = cache_control(private=True, public=True) urlpatterns = patterns('', (r'^foo/$', open_cache(foo_view)), # ... )