Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
3  nap/cache/base.py
@@ -14,7 +14,7 @@ def __init__(self, default_timeout=DEFAULT_TIMEOUT, obey_cache_headers=True):
def get(self, key):
return None
- def set(self, key, value):
+ def set(self, key, value, response=None):
return None
def get_timeout_from_header(self, response):
@@ -28,7 +28,6 @@ def get_timeout_from_header(self, response):
def get_cache_key(self, model, url):
resource_name = model._meta['resource_name']
- root_url = model._meta['root_url']
key_parts = {
'resource_name': resource_name,
View
2  nap/cache/django_cache.py
@@ -10,10 +10,8 @@
class DjangoCacheBackend(BaseCacheBackend):
def get(self, key):
- print "get key: ", key
return cache.get(key)
def set(self, key, value, response=None):
- print "set key: ", key
timeout = self.get_timeout(response)
return cache.set(key, value, timeout)
View
7 nap/engine.py
@@ -472,7 +472,12 @@ def cache_response(self, response):
url=response.url,
)
- self.cache.set(cache_key, response)
+ # Cache backends are meant to possibly store more than just
+ # NapResponse objects, so if future features need to cache
+ # anything else it's possible.
+ # Thus, we pass response both as `value` and the response
+ # object
+ self.cache.set(cache_key, response, response=response)
@property
def logger(self):
View
9 tests/test_engine.py
@@ -292,10 +292,13 @@ def test_set_cache_from_response(self, *mocks):
request_method='GET',
)
req.return_value = response
- expected_cache_key = SampleResourceModel.objects.cache.get_cache_key(SampleResourceModel, response.url)
- res = SampleResourceModel.objects.get_from_uri('some-url/')
+ expected_cache_key = SampleResourceModel.objects.cache.get_cache_key(
+ SampleResourceModel,
+ response.url,
+ )
+ SampleResourceModel.objects.get_from_uri('some-url/')
- cache_set.assert_called_with(expected_cache_key, response)
+ cache_set.assert_called_with(expected_cache_key, response, response=response)
@mock.patch('nap.engine.ResourceEngine._request')
@mock.patch('nap.cache.base.BaseCacheBackend.set')

No commit comments for this range

Something went wrong with that request. Please try again.