Google App Engine的Memcache(Java)是全局缓存吗? [英] Is Memcache (Java) for Google App Engine a global cache?

查看:124
本文介绍了Google App Engine的Memcache(Java)是全局缓存吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google App Engine的新手,最近几天我使用GAE的Memcache构建应用程序来存储数据。根据我最初的研究结果,看起来GAE的Memcache不是全球性的?

让我进一步解释。我意识到对GAE的不同请求可能会由不同的实例提供服务(实际上这似乎经常发生)。正是出于这个原因,我使用Memcache来存储一些共享数据,而不是静态的Map。我想(可能是错误的),这是使用分布式缓存的重点,以便数据可以被任何节点访问。



另一个确定的可能性是我在做有问题。我已经尝试了JCache和低级Memcache API(我正在编写Java,而不是Python)。这是我正在做的检索缓存:

  MemcacheService cache = MemcacheServiceFactory.getMemcacheService(); 

部署之后,这就是我检查的内容(通过我的应用程序日志):


  1. 初始请求由特定节点提供,数据存储在上面检索的缓存中。
  2. 请求检索这个相同的缓存并且数据在那里。

  3. 当一个新节点被派生为一个请求提供服务时(我知道这种情况发生的原因,因为GAE记录了导致一个新的进程开始为您的应用程序..),缓存检索,并已空!

现在我也知道无法保证数据在Memcache中的存储时间,但根据我的发现,在diff实例试图访问缓存时数据似乎不存在。这似乎违背了分布式全局缓存的整个概念no?



希望有人能够澄清这个应该如何表现。如果Memcache不是全局的,并且每个服务器实例都有自己的副本,那么为什么要使用Memcache?我可以简单地使用一个静态HashMap(我最初做的直到我意识到它不会是全局的,因为不同的实例服务我的请求)。

帮助? Memcache 在应用程序的所有实例中共享。


I'm new to Google App Engine, and I've spent the last few days building an app using GAE's Memcache to store data. Based on my initial findings, it appears as though GAE's Memcache is NOT global?

Let me explain further. I'm aware that different requests to GAE can potentially be served by different instances (in fact this appears to happen quite often). It is for this reason, that I'm using Memcache to store some shared data, as opposed to a static Map. I thought (perhaps incorrectly) that this was the point of using a distributed cache so that data could be accessed by any node.

Another definite possibility is that I'm doing something wrong. I've tried both JCache and the low-level Memcache API (I'm writing Java, not Python). This is what I'm doing to retrieve the cache:

MemcacheService cache = MemcacheServiceFactory.getMemcacheService();

After deployment, this is what I examine (via my application logs):

  1. The initial request is served by a particular node, and data is stored into the cache retrieved above.
  2. The new few requests retrieve this same cache and the data is there.
  3. When a new node gets spawned to serve a request (from the logs I know when this happens because GAE logs the fact that "This request caused a new process to be started for your application .."), the cache is retrieved and is EMPTY!!

Now I also know that there is no guarantee to how long data will be in Memcache, but from my findings it appears the data is gone the moment a diff instance tries to access the cache. This seems to go against the whole concept of a distributed global cache no?

Hopefully someone can clarify exactly how this SHOULD behave. If Memcache is NOT suppose to be global and every server instance has its own copy, then why even use Memcache? I could simply use a static HashMap (which I initially did until I realized it wouldn't be global due to different instances serving my requests).

Help?

解决方案

Yes, Memcache is shared across all instances of your app.

这篇关于Google App Engine的Memcache(Java)是全局缓存吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆