保存memcache数据后,是否可以立即在GAE上使用?
在Google App Engine(python)上,我需要使用memcache保存数据并在另一个页面上快速读取它。
但在我开始编码以保存内存缓存之前,然后在下一页上我使用已知密钥打开该数据,我开始怀疑数据是否会始终存在于下一页上?缓存数据并可靠地出现在下一页上需要多长时间才能读取?这是一个问题,因为它是云服务,或者即使它在一台服务器上也会是一个问题吗?或者这根本不是问题,我可以指望它出现在下一页上?
注意:此方法不是我的网络应用程序的主干,它只是我需要在一个场景中使用的一种特殊情况。另外,对于这种情况,我不想使用查询字符串、cookie 或标头值在页面之间保留数据。
On Google App Engine (python), I need to save data with memcache and quickly read it on another page.
But before I start coding to have memcache saved, then on the next page I open up that data with the known key, I'm starting to wonder if the data will always be there on the next page? How long does it take to cache the data, and reliably be there on the next page to read? Is this an issue since it's a cloud service, or would this be an issue even if it was on one server? Or is it not an issue at all and I can count on it being there on the next page?
NOTE: This method isn't the backbone of my webapp, its just a special case I need to use for one scenario. Also, for this scenario I do not want to persist data between pages with a querystring, cookies or header values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
分布式内存缓存架构有一个内存缓存实例池,为所有 Google App Engine 应用程序提供服务;存储的数据不会在内存缓存服务器之间复制。
在 memcache 上成功保存数据后,您的数据将在任何后续请求中*,因为它存储在一个特定的 memcache 实例中。
* 一个警告:如果内存不足,值可能会从缓存中逐出
The distributed memcache architecture has a pool of memcache instances that serves all the Google App Engine applications; the stored data is not replicated between memcache servers.
After successfully saving data on memcache, your data will be there* for any subsequent requests because it is stored in one specific memcache instance.
* one caveat: values may be evicted from the cache in case of low memory
我不认为 memcached 的 GAE 实现有什么特别之处,因此缓存的值在设置后将立即可用,所以是的,它将在下一页上可用,除非它因 memcached 服务器达到内存限制而过期。谷歌似乎并没有限制你可以在内存缓存中存储多少数据,只限制你可以发出的请求数量,所以实际上我怀疑这是一个问题。
依赖可用的缓存值并不是一个好的做法,在所有情况下,您都应该使用如下所示的模式。
I don't believe there is anything special with the GAE implementation of memcached so cached values will be available immediately after they are set, so yes, it will be available on the next page unless it is expired because the memcached server hit it's memory limit. Google don't appear to limit how much data you can store in memcache, only the number of requests you can make so in reality I doubt that this is a problem.
It is not good practice to rely on a cached value being available, in all cases you should use a pattern like the one below.
实际上,这些数据可能大部分时间都在那里,但在设计上您不能指望它 - 请参阅 文档:
(强调我的)
In practice, that data will probably be there most of the time, but you cannot count on it, by design -- see the docs:
(emphasis mine)