Google App Engine - Memcache - How likely am I to lose data in this scenario?
I want to store data with every request (what user viewed what page of my site).
With each request I will put the data (~100 bytes) in the memcache.
Every 5 seconds I will persist that data from the memcache to the datastore.
How rare would data loss开发者_JAVA百科 be in this scenario?
You basically can't trust memcache to keep your data at all. It's just a cache, after all, and can choose to evict data whenever it feels it is nessecary.
Having said that, in your particular scenario, the worst that will happen is you will lose 5 seconds worth of data. I don't think that's a big deal if you're just storing "pageview" data. Besides, unless the cache is running out of memory, there's really no need for it to evict data and so it's probably going to be fairly rare.
That depends on how heavily your app uses memcache for other things. Instead of this approach, though, I would suggest using task queues to store the data to the datastore for each request, without slowing the user-facing request down.
Do not trust memcached to remember your things for later. If you want something persisted then persist it there and then.
精彩评论