开发者

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 appe开发者_C百科ngine 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜