Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1494

Show
Ignore:
Timestamp:
12/09/06 16:35:26
Author:
fumanchu
Message:

2.x fix for #509 (don't cache for POST, PUT, DELETE). Also found a bug which I'll fix in trunk next.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-2.x/cherrypy/filters/cachefilter.py

    r1482 r1494  
    9595                # can't add because the queue is full 
    9696                return 
     97     
     98    def delete(self): 
     99        self.cache.pop(self.key) 
    97100 
    98101 
     
    111114    def before_main(self): 
    112115        if not cherrypy.config.get('cache_filter.on', False): 
     116            return 
     117         
     118        request = cherrypy.request 
     119         
     120        # POST, PUT, DELETE should invalidate (delete) the cached copy. 
     121        # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10. 
     122        if request.method in cherrypy.config.get("cache_filter.invalid_methods", 
     123                                                 ("POST", "PUT", "DELETE")): 
     124            cherrypy._cache.delete() 
    113125            return 
    114126         
     
    118130            expirationTime, lastModified, obj = cacheData 
    119131            s, h, b = obj 
    120             modifiedSince = cherrypy.request.headers.get('If-Modified-Since', None) 
     132            modifiedSince = request.headers.get('If-Modified-Since', None) 
    121133            if modifiedSince is not None and modifiedSince == lastModified: 
    122134                cherrypy._cache.totNonModified += 1 
     
    128140            else: 
    129141                # serve it & get out from the request 
    130                 cherrypy.response.status, cherrypy.response.header_list, body = s, h, b 
    131                 cherrypy.response.body = body 
     142                response = cherrypy.response 
     143                response.status, response.header_list, response.body = s, h, b 
    132144            raise cherrypy.RequestHandled() 
    133145        else: 
    134             cherrypy.request.cacheable = True 
     146            request.cacheable = True 
    135147     
    136148    def before_finalize(self): 
  • branches/cherrypy-2.x/cherrypy/test/test_cache_filter.py

    r1017 r1494  
    3434            # The response should be the same every time! 
    3535            self.assertBody('visit #1') 
     36         
     37        # POST, PUT, DELETE should not be cached. 
     38        self.getPage("/", method="POST") 
     39        self.assertBody('visit #2') 
     40        # The previous request should have invalidated the cache, 
     41        # so this request will recalc the response. 
     42        self.getPage("/", method="GET") 
     43        self.assertBody('visit #3') 
     44        # ...but this request should get the cached copy. 
     45        self.getPage("/", method="GET") 
     46        self.assertBody('visit #3') 
     47        self.getPage("/", method="DELETE") 
     48        self.assertBody('visit #4') 
     49        # The previous request should have invalidated the cache, 
     50        # so this request will recalc the response. 
     51        self.getPage("/", method="GET") 
     52        self.assertBody('visit #5') 
     53 
    3654 
    3755if __name__ == '__main__': 

Hosted by WebFaction

Log in as guest/cpguest to create tickets