Skip to content

Commit 538078d

Browse files
ryanmatsJon Wayne Parrott
authored andcommitted
Updated memcache error checking to handle large object exception (GoogleCloudPlatform#748)
1 parent fcdb9ea commit 538078d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

appengine/standard/memcache/guestbook/app.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# https://developers.google.com/appengine/docs/python/config/appconfig
44
# for details.
55

6-
version: 1
76
runtime: python27
87
api_version: 1
98
threadsafe: yes

appengine/standard/memcache/guestbook/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,13 @@ def get_greetings(self, guestbook_name):
8585
greetings = memcache.get('{}:greetings'.format(guestbook_name))
8686
if greetings is None:
8787
greetings = self.render_greetings(guestbook_name)
88-
if not memcache.add('{}:greetings'.format(guestbook_name),
89-
greetings, 10):
90-
logging.error('Memcache set failed.')
88+
try:
89+
added = memcache.add(
90+
'{}:greetings'.format(guestbook_name), greetings, 10)
91+
if not added:
92+
logging.error('Memcache set failed.')
93+
except ValueError:
94+
logging.error('Memcache set failed - data larger than 1MB')
9195
return greetings
9296
# [END check_memcache]
9397

0 commit comments

Comments
 (0)