2 Replies Latest reply on Nov 25, 2007 4:27 AM by Robert Nebauer

    How to set expiry time for s:cache?

    stef B Newbie

      I use <s:cache>. How to set expiry time for cached fragment?
      Is that tag can work with TreeCache or work only with PojoCache?
      And can I use and ExpiritionPolicy ?

        • 1. Re: How to set expiry time for s:cache?
          Pete Muir Master

          You can specify the region into which to cache the data, this region can have an expiration policy associated. Read the JBoss Cache manual for more. s:cache is based on PojoCache.

          • 2. Re: How to set expiry time for s:cache?
            Robert Nebauer Newbie

            I'm using this treecache.xml with success:

            <?xml version="1.0" encoding="UTF-8"?>
            <server>
             <mbean code="org.jboss.cache.TreeCache"
             name="jboss.cache:service=TreeCache">
             <depends>jboss:service=Naming</depends>
             <depends>jboss:service=TransactionManager</depends>
            
             <!-- Configure the TransactionManager -->
             <attribute name="TransactionManagerLookupClass">
             org.jboss.cache.JBossTransactionManagerLookup
             </attribute>
            
             <!-- Specific eviction policy configurations. -->
             <attribute name="EvictionPolicyConfig">
             <config>
             <attribute name="wakeUpIntervalSeconds">5</attribute>
            
             <!-- Cache wide default -->
             <region name="/_default_"
             policyClass="org.jboss.cache.eviction.LRUPolicy">
             <!-- This is the maximum number of nodes allowed in this region. -->
             <!-- 0 denotes no limit. -->
             <attribute name="maxNodes">0</attribute>
            
             <!-- The amount of time a node is not written to or read (in seconds) before the node is swept away. -->
             <!-- 0 denotes no limit. -->
             <attribute name="timeToLiveSeconds">0</attribute>
            
             <!-- Lifespan of a node (in seconds) regardless of idle time before the node is swept away. -->
             <!-- 0 denotes no limit. -->
             <attribute name="maxAgeSeconds">0</attribute>
             </region>
            
             <region name="/5sec"
             policyClass="org.jboss.cache.eviction.LRUPolicy">
             <attribute name="maxNodes">0</attribute>
             <attribute name="timeToLiveSeconds">0</attribute>
             <attribute name="maxAgeSeconds">5</attribute>
             </region>
             </config>
             </attribute>
             </mbean>
            </server>
            


            Code for testing:

             <table border="1">
             <tr>
             <td><b>Short term cache ('/5sec'):</b></td>
             <td>
             <s:cache region="/5sec" key="now" enabled="true">
             <h:outputText value="#{form.info.now()}" />
             </s:cache>
             </td>
             </tr>
             <tr>
             <td><b>Long term cache ('/forever'):</b></td>
             <td>
             <s:cache region="/forever" key="now" enabled="true">
             <h:outputText value="#{form.info.now()}" />
             </s:cache>
             </td>
             </tr>
             </table>