[Python] [django] max_age cache control dinamico

Marco Beri marcoberi a gmail.com
Mar 15 Gen 2013 14:40:50 CET


On Tue, Jan 15, 2013 at 2:23 PM, Andrea Ambu <andreambu a gmail.com> wrote:

> Ciao!
> Dunque si puo` facilmente controllare la max_age per una view cosi`:
>
> """""""""""
> from django.views.decorators.cache import cache_control
>
> @cache_control(max_age=3600)
> def my_view(request):
>     # ...
>
> """""""""""
>
> Ma se volessi che il valore di max_age venga deciso _dentro_ my_view come
> posso fare?
>
> Per esempio:
> """""""""""
> def my_view(request):
>     if is_good_to_keep_in_cache_for_a_bit(request):
>         # set max_age to 36000
>     else:
>         # set max_age to 42
>     # ...
> """""""""""
>

Boh, potresti importare patch_cache_control da django.utils.cache.py e fare:

    response = patch_cache_control(response, max_age=<quello che vuoi>)

Oppure provare a passare una property come valore di max_age.

Entrambe idee non provate: lascio al lettore l'onere della prova :-)

Ciao.
Marco.

-- 
http://beri.it/ - Un blog
http://beri.it/i-miei-libri/ - Qualche libro
-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://lists.python.it/pipermail/python/attachments/20130115/94c55c0b/attachment.html>


Maggiori informazioni sulla lista Python