Skip to content

Commit

Permalink
update cache in EsiApp if 304, fix headers case for client
Browse files Browse the repository at this point in the history
related #40
  • Loading branch information
Kyria committed May 24, 2018
1 parent a131251 commit 94d4018
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion esipy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
# Not installed or in install (not yet installed) so ignore
pass

__version__ = '0.4.0'
__version__ = '0.4.1'
12 changes: 9 additions & 3 deletions esipy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,23 @@ def __get_or_create_app(self, url, cache_key):
0 < self.expire < time.time()) and etag is None):
self.cache.invalidate(cache_key)

# set timeout value in case we have to cache it later
timeout = 0
if self.expire is not None and self.expire > 0:
timeout = time.time() + self.expire

# we are here, we know we have to make a head call...
res = requests.head(app_url, headers=headers)
if res.status_code == 304 and cached_app is not None:
self.cache.set(
cache_key,
(cached_app, res.headers, timeout)
)
return cached_app

# ok, cache is not accurate, make the full stuff
app = App.create(app_url)
if self.caching:
timeout = 0
if self.expire is not None and self.expire > 0:
timeout = time.time() + self.expire
self.cache.set(cache_key, (app, res.headers, timeout))

return app
Expand Down
4 changes: 2 additions & 2 deletions esipy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def __make_request(self, request, opt, cache_key=None, method=None):
# if we have HTTP 304 (content didn't change), return the cached
# response updated with the new headers
if res.status_code == 304 and cached_response is not None:
cached_response.headers['expires'] = res.headers.get('expires')
cached_response.headers['date'] = res.headers.get('date')
cached_response.headers['Expires'] = res.headers.get('Expires')
cached_response.headers['Date'] = res.headers.get('Date')
return cached_response
return res

0 comments on commit 94d4018

Please sign in to comment.