Reputation: 4331
I want to operate some data in memory/memcache. Importantly, I want not to loose that data so I'd like to save it to a persistent storage when GAE decides to unload it from memory.
Am I right there is no way to detect memcached object unload event for GAE?
May I still override __del__()
to save a global variable's value to datastore? (It's hard to verify this case for me.)
Upvotes: 0
Views: 99
Reputation: 16890
I'm sorry, but this is entirely the wrong way to go about it. The right thing is to write the data to the datastore and memcache, and later try to read it from memcache and if it isn't there to read it from the datastore and write it back to memcache.
Overloading __del__
is also a bad idea; it's a bad idea in general, and for this purpose it's disastrous, as there are any number of reasons why your process may be terminated without invoking any __del__
methods. (E.g. hard out-of-memory conditions, hard crashes of Python or the Linux kernel, hardware failures, and so on.)
If you want an easy way to integrate memcache and datastore without having to think about it, try NDB - it does this transparently for you.
Upvotes: 4