Configuring 2 SimplePageFragmentCachingFilter

kikuman
2009-09-07
2013-08-14
  • kikuman

    kikuman - 2009-09-07

    Hi,
    I'm new to ehcache and the what I'm trying to accomplish is pretty basic I believe.
    I'd like to configure two "SimplePageFragmentCachingFilter"s, with different "timeToLiveSeconds" values, for two different jsp:includes.
    I'm using ehcache-1.6.2 and ehcache-web-1.6.0-beta2, in a usual J2EE app.
    Here's what my web.xml and ehcache.xml look like:
    In web.xml:
    <filter>
            <filter-name>SimplePageFragmentCachingFilter</filter-name>
            <filter-class>net.sf.ehcache.constructs.web.filter.SimplePageFragmentCachingFilter</filter-class>
        </filter>

        <filter-mapping>
            <filter-name>SimplePageFragmentCachingFilter</filter-name>
            <url-pattern>/WEB-INF/jsp/test.jsp</url-pattern>
            <dispatcher>INCLUDE</dispatcher>
        </filter-mapping>

        <filter>
            <filter-name>SimplePageFragmentCachingFilter0</filter-name>
            <filter-class>net.sf.ehcache.constructs.web.filter.SimplePageFragmentCachingFilter</filter-class>
            <init-param>
                <param-name>cacheName</param-name>
                <param-value>SimplePageFragmentCachingFilter0</param-value>
            </init-param>
        </filter>

        <filter-mapping>
            <filter-name>SimplePageFragmentCachingFilter0</filter-name>
            <url-pattern>/jsp/text.jsp</url-pattern>
            <dispatcher>INCLUDE</dispatcher>
        </filter-mapping>

    In ehcache.xml:
    <?xml version="1.0" encoding="UTF-8"?>

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="ehcache.xsd">
        <diskStore path="java.io.tmpdir"/>

        <defaultCache
                maxElementsInMemory="10"
                eternal="false"
                timeToIdleSeconds="5"
                timeToLiveSeconds="10"
                overflowToDisk="true"
                />

        <cache name="SimplePageFragmentCachingFilter0"
               maxElementsInMemory="10"
               eternal="false"
               timeToIdleSeconds="0"
               timeToLiveSeconds="5"
               overflowToDisk="true">
        </cache>

        <cache name="SimplePageFragmentCachingFilter"
               maxElementsInMemory="10"
               eternal="false"
               timeToIdleSeconds="0"
               timeToLiveSeconds="20"
               overflowToDisk="true">
        </cache>
    </ehcache>

    What I noticed, is that both caches expire after 20 seconds.
    Any help would be greatly appreciated,
    Thanks
    Alex.

     
    • kikuman

      kikuman - 2009-09-07

      I think I've figured it out. I read "Configuring the cacheName" section of http://ehcache.org/documentation/web_caching.html and subclassed SimplePageFragmentCachingFilter overriding getCacheName() method and returned "SimplePageFragmentCachingFilter0", also changed the one of the filters' declarations to:
      <filter>
              <filter-name>SimplePageFragmentCachingFilter0</filter-name>
              <filter-class>sametinget.SimplePageFragmentCachingFilter0</filter-class>
      </filter>

      Cheers :)

       
  • suchetana basu

    suchetana basu - 2013-08-14

    Hello Kikuman,

    I am having issues in testing the above scenario.

    I am using play framework
    Below attached is my web.xml and ehcache.xml-

    I think if I am loading an html having _leftnavigation.html as a fragment of the html then _leftnavigation.html should be cached and any change in the html made immediately should not be reflecting.

    But this is not the scenario. So is it that my implementation is incorrect or is it that I am testing the wrong way???

    Please respond as early as possible.

     
    Last edit: suchetana basu 2013-08-14
    Attachments

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks