Ehcache 3 简单网页缓存的过滤器在哪里调用缓存?
Where does the filter for Ehcache 3 simple web page caching call the cache?
我正在尝试在 Ehcache 中缓存一个简单的网页。感谢另一个 SO post 的帮助,我发现我需要基于 Ehcache 2 代码实现我自己的过滤器。当我看 filter 时,我不明白。它在哪里调用缓存以 return 一个值?这是我的实现(很可能是错误的):
package com.sentiment360.pulse.cache;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.Element;
import org.ehcache.Cache;
import org.ehcache.CacheManager;
import org.ehcache.config.Configuration;
import static org.ehcache.config.builders.CacheManagerBuilder.newCacheManager;
import org.ehcache.core.Ehcache;
import org.ehcache.event.CacheEvent;
import org.ehcache.event.CacheEventListener;
import org.ehcache.xml.XmlConfiguration;
import javax.servlet.http.HttpServletRequest;
public class SimplePageCachingFilter implements CachingFilter {
public static final String DEFAULT_CACHE_NAME = "SimplePageCachingFilter";
private Logger LOG = Logger.getLogger(this.getClass().getName());
private String cacheName="basicCache";
protected String getCacheName() {
if (cacheName != null && cacheName.length() > 0) {
LOG.log(Level.INFO,"Using configured cacheName of {}.", cacheName);
return cacheName;
} else {
LOG.log(Level.INFO,"No cacheName configured. Using default of {}.", DEFAULT_CACHE_NAME);
return DEFAULT_CACHE_NAME;
}
}
protected CacheManager getCacheManager() {
return CacheManager.getInstance();
}
protected String calculateKey(HttpServletRequest httpRequest) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(httpRequest.getMethod()).append(httpRequest.getRequestURI()).append(httpRequest.getQueryString());
String key = stringBuffer.toString();
return key;
}
}
见super class。
但是你implements CachingFilter
?!那个界面在哪里?看起来您确实在尝试 "copy" 以前的 Ehcache 的 SimplePageCachingFilter
,对吗?您还需要移植那个抽象的超级 class(并且可能阅读一些关于 javax.servlet.Filter
的内容,以防这些不完全清楚...)
现在,您可能还想就此在 Ehcache Dev Google group 上联系开发团队。他们应该能够提供指导,然后帮助实施。看起来是未来拉取请求的好主意! :)
我正在尝试在 Ehcache 中缓存一个简单的网页。感谢另一个 SO post 的帮助,我发现我需要基于 Ehcache 2 代码实现我自己的过滤器。当我看 filter 时,我不明白。它在哪里调用缓存以 return 一个值?这是我的实现(很可能是错误的):
package com.sentiment360.pulse.cache;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.Element;
import org.ehcache.Cache;
import org.ehcache.CacheManager;
import org.ehcache.config.Configuration;
import static org.ehcache.config.builders.CacheManagerBuilder.newCacheManager;
import org.ehcache.core.Ehcache;
import org.ehcache.event.CacheEvent;
import org.ehcache.event.CacheEventListener;
import org.ehcache.xml.XmlConfiguration;
import javax.servlet.http.HttpServletRequest;
public class SimplePageCachingFilter implements CachingFilter {
public static final String DEFAULT_CACHE_NAME = "SimplePageCachingFilter";
private Logger LOG = Logger.getLogger(this.getClass().getName());
private String cacheName="basicCache";
protected String getCacheName() {
if (cacheName != null && cacheName.length() > 0) {
LOG.log(Level.INFO,"Using configured cacheName of {}.", cacheName);
return cacheName;
} else {
LOG.log(Level.INFO,"No cacheName configured. Using default of {}.", DEFAULT_CACHE_NAME);
return DEFAULT_CACHE_NAME;
}
}
protected CacheManager getCacheManager() {
return CacheManager.getInstance();
}
protected String calculateKey(HttpServletRequest httpRequest) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(httpRequest.getMethod()).append(httpRequest.getRequestURI()).append(httpRequest.getQueryString());
String key = stringBuffer.toString();
return key;
}
}
见super class。
但是你implements CachingFilter
?!那个界面在哪里?看起来您确实在尝试 "copy" 以前的 Ehcache 的 SimplePageCachingFilter
,对吗?您还需要移植那个抽象的超级 class(并且可能阅读一些关于 javax.servlet.Filter
的内容,以防这些不完全清楚...)
现在,您可能还想就此在 Ehcache Dev Google group 上联系开发团队。他们应该能够提供指导,然后帮助实施。看起来是未来拉取请求的好主意! :)