maybe someone else in here can answer my question... I haven't
found nothing ready to use out of the box in py4web for caching
controller results client side so I thought to implement my self
following the cache.action decorator code in web2py, but without
success till now.
-------- Forwarded Message --------
Hi!
I wrote this little function trying to re-implementing client side
caching controller response behavior as the one is available in
web2py
(
https://github.com/web2py/web2py/blob/master/gluon/cache.py#L660)
using the cache.action decorator:
import datetime
from py4web import response as rsp
def asknomore(time_expire=60):
cache_control = 'max-age=%(time_expire)s,
s-maxage=%(time_expire)s' % dict(time_expire=time_expire)
cache_control += ', public' # if not session_ and public_ else
', private'
expires = (datetime.datetime.utcnow() +
datetime.timedelta(seconds=time_expire)).strftime('%a, %d %b %Y
%H:%M:%S GMT')
headers = {
'Pragma': None,
'Expires': expires,
'Cache-Control': cache_control
}
rsp.headers.update(headers)
and I'm using it inside a controller function just before
returning result:
@action('mycachedaction')
def mycachedaction():
asknomore(120)
return dict(message='Hello')
The headers seams correctly set in the response but reloading the
page I always get a status: 200 instead of 304
What I am missing?
Thanks a lot!
Manuele