【发布时间】:2014-04-19 14:07:25
【问题描述】:
这个问题的答案似乎很明显,但我需要完全确定。因此,如果答案可以提供权威的参考和明确无歧义的陈述,那就太好了。
假设我有以下两种方法
public CollectionResponse<Dog> getDogs(Identification request){
MemcacheService syncCacheDog = MemcacheServiceFactory.getMemcacheService();
syncCacheDog.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
// ........
value = (byte[]) syncCacheDog.get(key); // read from cache
if (value == null) {
// get value from other source
// ........
syncCacheDog.put(key, value); // populate cache
}
// ........
}
public CollectionResponse<Cat> getCats(Identification request){
MemcacheService syncCacheCat = MemcacheServiceFactory.getMemcacheService();
syncCacheCat.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
// ........
value = (byte[]) syncCacheCat.get(key); // read from cache
if (value == null) {
// get value from other source
// ........
syncCacheCat.put(key, value); // populate cache
}
// ........
}
syncCacheDog 和 syncCacheCat 是否指向同一个地图?或者如果我希望他们指向同一张地图,我是否必须创建
static MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
然后在两个方法中都使用syncCache?
另一方面,如果是单例,我该如何维护两个不同的缓存呢? IE。有人可以复制并粘贴我的一个方法并显示它是用命名空间编写的,而不是处理通用字节来处理特定对象(例如 Dog)吗?
【问题讨论】:
标签: java google-app-engine memcached google-cloud-endpoints