-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Updated memcache error checking to handle large object exception #748
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,9 +85,13 @@ def get_greetings(self, guestbook_name): | |
| greetings = memcache.get('{}:greetings'.format(guestbook_name)) | ||
| if greetings is None: | ||
| greetings = self.render_greetings(guestbook_name) | ||
| if not memcache.add('{}:greetings'.format(guestbook_name), | ||
| greetings, 10): | ||
| logging.error('Memcache set failed.') | ||
| try: | ||
| added = memcache.add( | ||
| '{}:greetings'.format(guestbook_name), greetings, 10) | ||
| if not added: | ||
| logging.error('Memcache set failed.') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we know for sure if memcache.add returning False is necessarily a 'key already exists' type of error? The docs say memcache.add returns 'False on error'. (https://cloud.google.com/appengine/docs/python/refdocs/modules/google/appengine/api/memcache#Client.add). Wondering if the False could mean something else in certain circumstances.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I don't know, I guess we can leave it as is. |
||
| except ValueError: | ||
| logging.error('Memcache set failed - data larger than 1MB') | ||
| return greetings | ||
| # [END check_memcache] | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since these are two separate cases, you want two separate error messages. Should be,
Memcache add failed, key already existsandMemcache add failed, data larger than 1MBThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a more specific message for data larger than 1MB.
For the memcache.add False result, it might not necessarily be a key already exists error, so I'm leaving it as 'Memcache set failed.'