Fwd: client side caching

24 views
Skip to first unread message

Manuele Pesenti

unread,
May 14, 2020, 7:52:00 AM5/14/20
to web2py-users

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...@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

Val K

unread,
May 14, 2020, 8:06:47 AM5/14/20
to web2py-users

Val K

unread,
May 14, 2020, 8:10:39 AM5/14/20
to web2py-users
Oh, sorry, it is about server side cache

Val K

unread,
May 14, 2020, 5:02:42 PM5/14/20
to web2py-users
But why do you think that it should be 304?

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304

Reply all
Reply to author
Forward
0 new messages