简体   繁体   中英

Pickling an object on appengine

I have an object with an __init__ procedure that requires at least one parameter and

I want to store in the cache.

When trying to getting the object from the cache I get an error that the I didn't pass enough parameters to the ___init___ method.

Someone told me I need to pickle the object before sending it to the cache but all the examples I saw were using.dat files and on appengine you cannot use any file system.

You can use pickle without any filesystem, using pickle.loads / pickle.dumps. For example:

import pickle
obj = YourClass(yourparam=...)
data = pickle.dumps(obj)
# and now, store "data" into the cache

# later, get "data" from the cache
obj = pickle.loads(data)

# and tada, obj if the same as before :)

I think you are trying to use memcache in appengine. This blog will help you a lot

http://blog.notdot.net/2009/9/Efficient-model-memcaching

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM