Is it possible to set Cache-Control: no-cache using @cache.action decorator?

39 views
Skip to first unread message

Lisandro

unread,
Jul 21, 2017, 2:24:33 PM7/21/17
to web2py-users
Maybe my question is wrong because of some background that I'm not seeing.
Due to the structure of my app, I use @cache.action like this in all my controller functions:

@cache.action(cache_model=CACHE.model, time_expire=CACHE.time_expire, session=CACHE.session, vars=CACHE.vars, public=CACHE.public)
def index():
   
# code here

In my model, I define the CACHE object with the proper attributes, depending on several situations (logged in or not, certain permissions, specific scenarios). The thing is that, in some cases I need to set the response headers as if I hadn't use @cache.action. I've tried to set cache_model=None and time_expire=None, but it throws the following error:

Traceback (most recent call last):
File "/home/gonguinguen/medios/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/home/gonguinguen/medios/applications/mazar/controllers/default.py", line 463, in <module>
File "/home/gonguinguen/medios/gluon/globals.py", line 417, in <lambda>
self._caller = lambda f: f()
File "/home/gonguinguen/medios/gluon/cache.py", line 669, in wrapped_f
'Expires': expires,
UnboundLocalError: local variable 'expires' referenced before assignment


I mean, if I dont use @cache.action, then Cache-Control header has the following value:
no-store, no-cache, must-revalidate, post-check=0, pre-check=0

But I can't generate that same response header using @cache.action.
Wouldn't be nice if we could pass time_expire=0 and cache_model=None to set those headers?

In anycase, how can I solve it? Would I need a custom decorator? Would it be possible to instantiate and rewrite the default cache.action behaviour?

Thanks in advance!
Regards,
Lisandro

Lisandro

unread,
Jul 22, 2017, 9:07:20 AM7/22/17
to web2py-users
I've found that this is possible with a very simple modification to gluons/cache.py:

I don't know if I did right proposing that change.
Anyway, I just wanted to comment in case someone runs into some similar situation.
For the moment, I will instantiate Cache class and make my own cache object, that is, my own @cache.action decorator.

Regards, 
Lisandro
Reply all
Reply to author
Forward
0 new messages