<div dir="ltr">On Tue, Jan 15, 2013 at 2:23 PM, Andrea Ambu <span dir="ltr"><<a href="mailto:andreambu@gmail.com" target="_blank">andreambu@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px">
Ciao!</div><div style="font-family:arial,sans-serif;font-size:13px">Dunque si puo` facilmente controllare la max_age per una view cosi`:<br></div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">"""""""""""</div><div style="font-family:arial,sans-serif;font-size:13px">
from django.views.decorators.cache import cache_control</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">@cache_control(max_age=3600)</div><div style="font-family:arial,sans-serif;font-size:13px">
def my_view(request):</div><div style="font-family:arial,sans-serif;font-size:13px"> # ...</div><div style="font-family:arial,sans-serif;font-size:13px"><br>"""""""""""<br>
</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Ma se volessi che il valore di max_age venga deciso _dentro_ my_view come posso fare?</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Per esempio:</div><div style="font-family:arial,sans-serif;font-size:13px">"""""""""""<br>
</div><div style="font-family:arial,sans-serif;font-size:13px">def my_view(request):</div><div style="font-family:arial,sans-serif;font-size:13px"> if is_good_to_keep_in_cache_for_a_bit(request):</div><div style="font-family:arial,sans-serif;font-size:13px">
# set max_age to 36000</div><div style="font-family:arial,sans-serif;font-size:13px"> else:</div><div style="font-family:arial,sans-serif;font-size:13px"> # set max_age to 42 </div><div style="font-family:arial,sans-serif;font-size:13px">
# ... </div><span style="font-family:arial,sans-serif;font-size:13px">"""""""""""</span></div></blockquote><div><br></div><div>Boh, potresti importare <span style="color:rgb(153,0,0);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;font-weight:bold;line-height:16px;white-space:pre-wrap">patch_cache_control</span> da <a href="http://django.utils.cache.py">django.utils.cache.py</a> e fare:</div>
<div><br></div><div> response = patch_cache_control(response, max_age=<quello che vuoi>)</div><div><br></div><div>Oppure provare a passare una property come valore di max_age.</div><div>
<br>Entrambe idee non provate: lascio al lettore l'onere della prova :-)</div><div><br></div><div>Ciao.<br>Marco.</div><div><br></div></div>-- <br><div><div><div><div><a href="http://beri.it/" target="_blank">http://beri.it/</a> - Un blog</div>
<div><a href="http://beri.it/i-miei-libri/" target="_blank">http://beri.it/i-miei-libri/</a> - Qualche libro</div><div><br></div></div></div></div>
</div></div>