cache_page that does nothing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from django.conf import settings
from django.views.decorators.cache import cache_page

if settings.DEBUG:
    def cache_page(delay):
        def rendered(view):
            def inner(request, *args, **kwargs):
                return view(request, *args, **kwargs)
            return inner
        return rendered

@cache_page(60 * 60) # 1 hour
def my_view(request):
    ...expensive calculation...

More like this

  1. New view decorator to only cache pages for anonymous users by vaughnkoch 1 year, 4 months ago
  2. Get the Django decorator/middleware cache key for given URL by s29 3 months ago
  3. Scalable and invalidateble cache_page decorator by marinho 2 years, 9 months ago
  4. Run and cache only one instance of a heavy request by farnsworth 1 year, 5 months ago
  5. Effective content caching for mass-load site using redirect feature by nnseva 7 months, 1 week ago

Comments

gregb (on August 20, 2009):

Or you could just go

if DEBUG:
    CACHE_BACKEND = 'dummy://'

in your settings file. :)

docs here

#

larin (on August 21, 2009):

@gregb

+100 =)))

#

(Forgotten your password?)