Changeset 1443
- Timestamp:
- 11/22/06 13:36:08
- Files:
-
- trunk/cherrypy/lib/caching.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/caching.py
r1350 r1443 76 76 if (obj_size < maxobj_size and total_size < maxsize): 77 77 # add to the expirations list and cache 78 expiration_time = time.time()+ conf("tools.caching.delay", 600)78 expiration_time = cherrypy.response.time + conf("tools.caching.delay", 600) 79 79 obj_key = self.key 80 80 bucket = self.expirations.setdefault(expiration_time, []) … … 86 86 87 87 def get(invalid_methods=("POST", "PUT", "DELETE"), cache_class=MemoryCache): 88 """Try to obtain cached output. If fresh enough, raise HTTPError(304).""" 88 """Try to obtain cached output. If fresh enough, raise HTTPError(304). 89 90 If a cached copy exists: 91 * sets request.cached = True 92 * sets response.headers to the cached values 93 * checks the cached Last-Modified response header against the 94 current If-(Un)Modified-Since request headers; raises 304 95 if necessary. 96 * sets response.status and response.body to the cached values 97 * returns True 98 99 otherwise: 100 * sets request.cached = False 101 * returns False 102 """ 89 103 if not hasattr(cherrypy, "_cache"): 90 104 cherrypy._cache = cache_class() … … 95 109 # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10. 96 110 if request.method in invalid_methods: 97 request.cached = c = False 98 else: 99 cache_data = cherrypy._cache.get() 100 request.cached = c = bool(cache_data) 111 request.cached = False 112 return False 101 113 114 cache_data = cherrypy._cache.get() 115 request.cached = c = bool(cache_data) 102 116 if c: 103 117 response = cherrypy.response … … 105 119 106 120 # Add the required Age header 107 response.headers["Age"] = str(int( time.time()- create_time))121 response.headers["Age"] = str(int(response.time - create_time)) 108 122 109 123 try: 124 # Note that validate_since depends on a Last-Modified header; 125 # this was put into the cached copy, and should have been 126 # resurrected just above (response.headers = cache_data[1]). 110 127 cptools.validate_since() 111 128 except cherrypy.HTTPError, x: … … 135 152 # save the cache data 136 153 body = ''.join([chunk for chunk in output]) 137 create_time = time.time()138 154 cherrypy._cache.put((response.status, response.headers or {}, 139 body, create_time))155 body, response.time)) 140 156 response.body = tee(response.body) 141 157

