1

I'd like to cache my view as follows:

@cache_page(10)
def myview:
    return HttpResponse('content')

This automatically caches my view for 10 seconds and automatically sets Cache-Control/Expire header as well. I'd like to cache my view for only 10 seconds but have a max-age of 3600 seconds.

Tried it for example this way:

@cache_page(10)
def myview:
    response = HttpResponse('content')
    patch_response_headers(response, 3600)

or this way:

@cache_page(10)
def myview:
    response = HttpResponse('content')
    response['Cache-Control'] = 'max-age=3600'

But when specifying one of those within my Django-View it caches the view for 3600 seconds and not 10 seconds. Also tried decorators like 'cache_control' but nothing helps.

Is there a solution for this problem? I'm using Django 1.4.1.

Don't know if it is relavent, my activated middleware classes are

  • django.middleware.common.CommonMiddleware
  • django.contrib.sessions.middleware.SessionMiddleware
  • django.middleware.csrf.CsrfViewMiddleware
  • django.contrib.auth.middleware.AuthenticationMiddleware
  • django.contrib.messages.middleware.MessageMiddleware
  • django.middleware.http.ConditionalGetMiddleware

I've activated the ConditionalGetMiddleware to make sure a 304 will be sent depending on the last-modified header.

Thanks a lot!

Holger

holger359
  • 131
  • 1
  • 6

0 Answers0