【问题标题】:Where does the filter for Ehcache 3 simple web page caching call the cache?Ehcache 3 简单网页缓存的过滤器在哪里调用缓存?
【发布时间】:2018-01-30 22:45:54
【问题描述】:

我正在尝试在 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;
    }
}

【问题讨论】:

    标签: caching ehcache ehcache-3


    【解决方案1】:

    super class。 但是你会implements CachingFilter 吗?!那个界面在哪里?看起来您确实在尝试“复制”以前的 Ehcache 的 SimplePageCachingFilter,对吧?您还需要移植该抽象超类(并且可能阅读一些关于 javax.servlet.Filter 的内容,以防这些内容不完全清楚......)

    现在,您可能还想通过Ehcache Dev Google group 联系开发团队了解此问题。他们应该能够提供指针,然后帮助实施。对于未来的拉取请求来说,这看起来是个好主意! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-23
      • 1970-01-01
      • 2021-01-06
      • 2022-08-18
      相关资源
      最近更新 更多