Excuse me for the crossposting,

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.

I'll be glad for any siggestion

Cheers

    Manuele



-------- Forwarded Message --------
Subject:        client side caching
Date:   Wed, 13 May 2020 09:45:58 +0200
From:   Manuele Pesenti <manuele.pese...@gmail.com>
To:     py4web <py4...@googlegroups.com>



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

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/f205ff51-e515-9405-e425-518f2f5913c0%40gmail.com.

Reply via email to