views:

84

answers:

3

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 be in this scenario?

+2  A: 

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.

Dean Harding
+1  A: 

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.

Nick Johnson
A: 

Do not trust memcached to remember your things for later. If you want something persisted then persist it there and then.

Thorbjørn Ravn Andersen