0

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.

Community
  • 1
  • 1
hyang123
  • 1,208
  • 1
  • 13
  • 32
  • 1
    Guido's answer provides adequate solution. Did you even try it? – Peter Knego Jul 17 '14 at 06:08
  • Peter, I have read Guido's answer. Unfortunately I am having trouble comprehending the code; particular the shorthand format provided. I am a python/gae beginner. Though, I am currently slowly researching the topics involved in Guido's answer. – hyang123 Jul 17 '14 at 15:44
  • I think perhaps what I need to understand is how Guido's answer code would work with my Memcache query code. That is, how i should store and retrieve my query using Guido's code. – hyang123 Jul 17 '14 at 15:57
  • 2
    The code Guido provides is a replacement for using memcache directly. So instead of `memcache.set(key, value)` you would use `store(key, value)` (and similarly `retrieve(key)` instead of `memcache.get`. However, I would definitely recommend considering if working with and storing all the entities from the query is really what you want to be doing (it will not scale). – Patrick Costello Jul 17 '14 at 21:29

0 Answers0