Re: [CherryPy] #918: caching does not respect Cache-Control: max-age header

20 views
Skip to first unread message

CherryPy

unread,
May 14, 2009, 8:39:05 AM5/14/09
to cherrypy...@googlegroups.com
#918: caching does not respect Cache-Control: max-age header
-------------------------------------+--------------------------------------
Reporter: guest | Owner: fumanchu
Type: defect | Status: new
Priority: high | Milestone:
Component: CherryPy code | Resolution:
Keywords: cache-control cache age |
-------------------------------------+--------------------------------------
--
Ticket URL: <http://www.cherrypy.org/ticket/918>
CherryPy <http://www.cherrypy.org>
CherryPy - a pythonic, object-oriented HTTP framework

CherryPy

unread,
May 14, 2009, 9:46:41 AM5/14/09
to cherrypy...@googlegroups.com
#918: caching does not respect Cache-Control: max-age header
-------------------------------------+--------------------------------------
Reporter: guest | Owner: fumanchu
Type: defect | Status: new
Priority: high | Milestone:
Component: CherryPy code | Resolution:
Keywords: cache-control cache age |
-------------------------------------+--------------------------------------
Comment (by shau...@cern.ch):

The following lines inserted to caching.py at line 152 will fix this;
sorry I don't really know (yet?) how to commit this code formally:

#some people still use Pragma : no-cache to demand a fresh resource
pragma_no_cache=False
pragma_header=request.headers.get('Pragma')
if pragma_header:
pragma_values=[header.strip() for header in
pragma_header.split(',')]
for this_value in pragma_values:
if 'no-cache' in this_value:
pragma_no_cache=True
break
#added by shaun, look at cache-control
max_acceptable_age=MemoryCache.delay
age_seconds=int(response.time - create_time)
cache_control_header=request.headers.get('Cache-Control')
if cache_control_header:
#split string on commas to get the multiple words
cache_control_values=[header.strip() for header in
cache_control_header.split(',')]
#look for max-age
for this_value in cache_control_values:
if ('max-age' in this_value) and ('=' in this_value):
age_pair=[age.strip() for age in
this_value.split('=')]
if age_pair[1].isdigit():
max_acceptable_age=int(age_pair[1])
break

#return if the cache is older than the acceptable age
if (age_seconds > max_acceptable_age) or pragma_no_cache:
request.cached = False
request.cacheable = True
return False

# Add the required Age header
response.headers["Age"] = str(age_seconds)

CherryPy

unread,
May 14, 2009, 8:38:25 AM5/14/09
to cherrypy...@googlegroups.com
#918: caching does not respect Cache-Control: max-age header
---------------------------+------------------------------------------------
Reporter: guest | Owner: fumanchu
Type: defect | Status: new
Priority: high | Milestone:
Component: CherryPy code | Keywords: cache-control cache age
---------------------------+------------------------------------------------
With caching turned on, requesting a resource with 'Cache-Control: max-
age=0, must-revalidate' header still results in serving the original
cached result where one exists for the requested url.

CherryPy

unread,
Aug 19, 2009, 12:18:30 AM8/19/09
to cherrypy...@googlegroups.com
#918: caching does not respect Cache-Control: max-age header
-------------------------------------+--------------------------------------
Reporter: guest | Owner: fumanchu
Type: defect | Status: assigned
Priority: high | Milestone: 3.2
Component: CherryPy code | Resolution:
Keywords: cache-control cache age |
-------------------------------------+--------------------------------------
Changes (by fumanchu):

* milestone: => 3.2
* status: new => assigned

Comment:

Fixed in trunk in [2511]. Needs port to python3.

CherryPy

unread,
Aug 29, 2009, 3:17:26 PM8/29/09
to cherrypy...@googlegroups.com
#918: caching does not respect Cache-Control: max-age header
-------------------------------------+--------------------------------------
Reporter: guest | Owner: fumanchu
Type: defect | Status: closed
Priority: high | Milestone: 3.2
Component: CherryPy code | Resolution: fixed
Keywords: cache-control cache age |
-------------------------------------+--------------------------------------
Changes (by fumanchu):

* resolution: => fixed
* status: assigned => closed

Comment:

python3 port is in [2520].
Reply all
Reply to author
Forward
0 new messages