Skip to content

Commit d338acc

Browse files
committed
Allow configuring the methods CacheControlAdapter tries to cache.
1 parent fbc288d commit d338acc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cachecontrol/adapter.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ def __init__(self, cache=None,
2828
serializer=serializer,
2929
)
3030

31-
def send(self, request, **kw):
31+
def send(self, request, cacheable=('GET',), **kw):
3232
"""
3333
Send a request. Use the request information to see if it
3434
exists in the cache and cache the response if we need to and can.
3535
"""
36-
if request.method == 'GET':
36+
if request.method in cacheable:
3737
cached_response = self.controller.cached_request(request)
3838
if cached_response:
3939
return self.build_response(request, cached_response,
@@ -48,14 +48,15 @@ def send(self, request, **kw):
4848

4949
return resp
5050

51-
def build_response(self, request, response, from_cache=False):
51+
def build_response(self, request, response, from_cache=False,
52+
cacheable=('GET',)):
5253
"""
5354
Build a response by making a request or using the cache.
5455
5556
This will end up calling send and returning a potentially
5657
cached response
5758
"""
58-
if not from_cache and request.method == 'GET':
59+
if not from_cache and request.method in cacheable:
5960
# Check for any heuristics that might update headers
6061
# before trying to cache.
6162
if self.heuristic:

0 commit comments

Comments
 (0)