Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change cache key to account for key's modification time. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@ def proxy_s3_bucket(self, environ, start_response):

def fetch_s3_object(self, bucket, key):
m = hashlib.md5()
m.update(bucket+key)
cache_key = m.hexdigest()

conn = boto.connect_s3()

b = conn.get_bucket(bucket)
k = b.get_key(key)
if k == None:
Copy link
Owner

@rhelmer rhelmer Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if k is None:

return None
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should log.warn too.

m.update(bucket+key+k.last_modified)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces around +

cache_key=m.hexdigest()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space around =

if cache_key in self.cache:
self.logger.debug('cache hit for %s' % cache_key)
return self.cache[cache_key]
else:
self.logger.debug('cache miss for %s' % cache_key)

b = conn.get_bucket(bucket)
k = b.get_key(key)
if k:
obj = k.get_contents_as_string()
self.cache[cache_key] = obj
return obj
else:
return None
obj = k.get_contents_as_string()
self.cache[cache_key] = obj
return obj