我正在尝试在Ehcache中缓存一个简单的网页。感谢另一篇SO帖子的帮助,我发现我需要基于Ehcache 2代码实现自己的过滤器。当我看到filter时,我不理解它。它在哪里调用缓存返回值?这是我的实现(很可能是错误的):
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;
}
}
答案 0 :(得分:1)
见super class。
但你做implements CachingFilter
?!那个界面在哪里?看起来你试图“复制”以前的Ehcache SimplePageCachingFilter
,对吗?你还需要移植那个抽象的超类(并且可能会读一些关于javax.servlet.Filter
的内容,以防这些不完全清楚...)
现在,您可能还希望在Ehcache Dev Google group上对开发团队进行ping操作。他们应该能够提供指针,然后帮助实现。对于未来的拉动请求看起来是个好主意! :)