Changeset 1495
- Timestamp:
- 12/09/06 16:48:50
- Files:
-
- trunk/cherrypy/_cptools.py (modified) (1 diff)
- trunk/cherrypy/lib/caching.py (modified) (5 diffs)
- trunk/cherrypy/test/test_caching.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cptools.py
r1471 r1495 260 260 request.handler = None 261 261 else: 262 # Note the devious technique here of adding hooks on the fly 263 request.hooks.attach('before_finalize', _caching.tee_output, 264 priority = 90) 262 if request.cacheable: 263 # Note the devious technique here of adding hooks on the fly 264 request.hooks.attach('before_finalize', _caching.tee_output, 265 priority = 90) 265 266 _wrapper.priority = 20 266 267 trunk/cherrypy/lib/caching.py
r1443 r1495 83 83 self.tot_puts += 1 84 84 self.cursize = total_size 85 86 def delete(self): 87 self.cache.pop(self.key) 85 88 86 89 … … 88 91 """Try to obtain cached output. If fresh enough, raise HTTPError(304). 89 92 90 If a cached copy exists: 93 If POST, PUT, or DELETE: 94 * invalidates (deletes) any cached response for this resource 95 * sets request.cached = False 96 * sets request.cacheable = False 97 98 else if a cached copy exists: 91 99 * sets request.cached = True 100 * sets request.cacheable = False 92 101 * sets response.headers to the cached values 93 102 * checks the cached Last-Modified response header against the … … 99 108 otherwise: 100 109 * sets request.cached = False 110 * sets request.cacheable = True 101 111 * returns False 102 112 """ … … 106 116 request = cherrypy.request 107 117 108 # Ignore POST, PUT, DELETE.118 # POST, PUT, DELETE should invalidate (delete) the cached copy. 109 119 # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10. 110 120 if request.method in invalid_methods: 121 cherrypy._cache.delete() 111 122 request.cached = False 123 request.cacheable = False 112 124 return False 113 125 114 126 cache_data = cherrypy._cache.get() 115 127 request.cached = c = bool(cache_data) 128 request.cacheable = not c 116 129 if c: 117 130 response = cherrypy.response … … 138 151 139 152 def tee_output(): 140 if cherrypy.request.cached:141 return142 143 153 response = cherrypy.response 144 154 output = [] trunk/cherrypy/test/test_caching.py
r1278 r1495 81 81 self.getPage("/", method="POST") 82 82 self.assertBody('visit #2') 83 # The previous request should have invalidated the cache, 84 # so this request will recalc the response. 83 85 self.getPage("/", method="GET") 84 self.assertBody('visit #2') 86 self.assertBody('visit #3') 87 # ...but this request should get the cached copy. 88 self.getPage("/", method="GET") 89 self.assertBody('visit #3') 85 90 self.getPage("/", method="DELETE") 86 self.assertBody('visit #3') 87 91 self.assertBody('visit #4') 92 # The previous request should have invalidated the cache, 93 # so this request will recalc the response. 94 self.getPage("/", method="GET") 95 self.assertBody('visit #5') 96 88 97 def testExpiresTool(self): 89 98

