Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion appengine/standard/memcache/guestbook/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# https://developers.google.com/appengine/docs/python/config/appconfig
# for details.

version: 1
runtime: python27
api_version: 1
threadsafe: yes
Expand Down
10 changes: 7 additions & 3 deletions appengine/standard/memcache/guestbook/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Copy link
Copy Markdown
Contributor

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 exists and Memcache add failed, data larger than 1MB

Copy link
Copy Markdown
Contributor Author

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.'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just need -value already exists here right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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]

Expand Down