Google App Engine - Memcache - How likely am I to

2019-07-15 09:36发布

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?

3条回答
做个烂人
2楼-- · 2019-07-15 09:57

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.

查看更多
爷、活的狠高调
3楼-- · 2019-07-15 09:58

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

查看更多
Melony?
4楼-- · 2019-07-15 10:12

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.

查看更多
登录 后发表回答