I just suddenly got the Memcache 1MB limit ValueError
. I'm hoping to find a quick 'bandaid' solution before I learn more about serializing/pickling. I have never done any pickling, and actually not that familiar with memcache. I learned from Udacity's course.
I have done some research, and read some existing questions including Guido's Avoiding Memcache "1000000 bytes in length" limit on values
This is the code I use to save a NDB query into memcache:
def all_entities(self, update = False):
key = 'all_entities'
all_entities = memcache.get(key)
if all_entities is None or update:
all_entities = Entity.query().order(-Entity.created).fetch() # 1000+ items
all_entities = list(all_entities)
memcache.set(key, all_entities)
return all_entities
I have some other NDB queries which are similarly saved to the memcache. From my research, I understand that pickling
should be used in these circumstances. As my website is currently down, I would like to find a Band-Aid solution while I dedicate some to learn about better methods.
I have tried altering the query to fetch less items like this:
all_entities = Entity.query().order(-Entity.created).fetch(100)
But this does not seem to work.