You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2006/03/21 21:14:57 UTC

svn commit: r387610 - in /jakarta/jcs/trunk: src/java/org/apache/jcs/auxiliary/disk/jdbc/ src/java/org/apache/jcs/engine/memory/ src/test-conf/ src/test/org/apache/jcs/auxiliary/disk/jdbc/ xdocs/

Author: asmuts
Date: Tue Mar 21 12:14:54 2006
New Revision: 387610

URL: http://svn.apache.org/viewcvs?rev=387610&view=rev
Log:
added a jdbc disk cache properties file

Added:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java
    jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheShrink.ccf
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java
Modified:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManager.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java
    jakarta/jcs/trunk/xdocs/JDBCDiskCacheProperties.xml

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java?rev=387610&r1=387609&r2=387610&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java Tue Mar 21 12:14:54 2006
@@ -27,7 +27,6 @@
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Arrays;
-
 import java.util.List;
 import java.util.Set;
 
@@ -55,19 +54,19 @@
  * configurable.
  * 
  * <pre>
- *          drop TABLE JCS_STORE;
- *         
- *          CREATE TABLE JCS_STORE
- *          (
- *          CACHE_KEY             VARCHAR(250)          NOT NULL,
- *          REGION                VARCHAR(250)          NOT NULL,
- *          ELEMENT               BLOB,
- *          CREATE_TIME           DATE,
- *          CREATE_TIME_SECONDS   BIGINT,
- *          MAX_LIFE_SECONDS      BIGINT,
- *          IS_ETERNAL            CHAR(1),
- *          PRIMARY KEY (CACHE_KEY, REGION)
- *          );
+ *           drop TABLE JCS_STORE;
+ *          
+ *           CREATE TABLE JCS_STORE
+ *           (
+ *           CACHE_KEY             VARCHAR(250)          NOT NULL,
+ *           REGION                VARCHAR(250)          NOT NULL,
+ *           ELEMENT               BLOB,
+ *           CREATE_TIME           DATE,
+ *           CREATE_TIME_SECONDS   BIGINT,
+ *           MAX_LIFE_SECONDS      BIGINT,
+ *           IS_ETERNAL            CHAR(1),
+ *           PRIMARY KEY (CACHE_KEY, REGION)
+ *           );
  * </pre>
  * 
  * 
@@ -637,14 +636,18 @@
      * 
      * (now - create time) > max life seconds * 1000
      * 
+     * @return the number deleted
+     * 
      */
-    protected void deleteExpired()
+    protected int deleteExpired()
     {
+        int deleted = 0;
+
         try
         {
             long now = System.currentTimeMillis() / 1000;
             String sql = "delete from " + getJdbcDiskCacheAttributes().getTableName() + " where REGION = '"
-                + this.getCacheName() + "' and IS_ETERNAL = 'F' and (" + now + " - CREATE_TIME_SECONDS) > MAX_LIFE";
+                + this.getCacheName() + "' and IS_ETERNAL = 'F' and (" + now + " - CREATE_TIME_SECONDS) > MAX_LIFE_SECONDS";
             Connection con = DriverManager.getConnection( getPoolUrl() );
             Statement sStatement = null;
             try
@@ -652,7 +655,7 @@
                 sStatement = con.createStatement();
                 alive = true;
 
-                sStatement.executeUpdate( sql );
+                deleted = sStatement.executeUpdate( sql );
             }
             catch ( SQLException e )
             {
@@ -680,6 +683,8 @@
             log.error( "Problem removing all.", e );
             reset();
         }
+
+        return deleted;
     }
 
     /**

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java?rev=387610&r1=387609&r2=387610&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java Tue Mar 21 12:14:54 2006
@@ -39,7 +39,7 @@
     private String url;
 
     private String database = "";
-    
+
     private String driverClassName;
 
     private String tableName = DEFAULT_TABLE_NAME;
@@ -47,9 +47,15 @@
     private boolean testBeforeInsert = true;
 
     private static final int DEFAULT_MAX_ACTIVE = 10;
-    
-    private int maxActive = DEFAULT_MAX_ACTIVE;   
-    
+
+    private int maxActive = DEFAULT_MAX_ACTIVE;
+
+    private static final int DEFAULT_SHRINKER_INTERVAL_SECONDS = 300;
+
+    private int shrinkerIntervalSeconds = DEFAULT_SHRINKER_INTERVAL_SECONDS;
+
+    private boolean UseDiskShrinker = true;
+
     /**
      * @param userName
      *            The userName to set.
@@ -103,7 +109,9 @@
 
     /**
      * This is appended to the url.
-     * @param database The database to set.
+     * 
+     * @param database
+     *            The database to set.
      */
     public void setDatabase( String database )
     {
@@ -153,8 +161,9 @@
     }
 
     /**
-     * If this is true then the disk cache will check to see if the item already exists in the database.
-     * If it is false, it will try to insert.  If the isnert fails it will try to update.
+     * If this is true then the disk cache will check to see if the item already
+     * exists in the database. If it is false, it will try to insert. If the
+     * isnert fails it will try to update.
      * 
      * @param testBeforeInsert
      *            The testBeforeInsert to set.
@@ -173,7 +182,8 @@
     }
 
     /**
-     * @param maxActive The maxActive to set.
+     * @param maxActive
+     *            The maxActive to set.
      */
     public void setMaxActive( int maxActive )
     {
@@ -189,6 +199,43 @@
     }
 
     /**
+     * @param shrinkerIntervalSecondsArg
+     *            The shrinkerIntervalSeconds to set.
+     */
+    public void setShrinkerIntervalSeconds( int shrinkerIntervalSecondsArg )
+    {
+        if ( shrinkerIntervalSecondsArg > 1 )
+        {
+            this.shrinkerIntervalSeconds = shrinkerIntervalSecondsArg;
+        }
+    }
+
+    /**
+     * @return Returns the shrinkerIntervalSeconds.
+     */
+    public int getShrinkerIntervalSeconds()
+    {
+        return shrinkerIntervalSeconds;
+    }
+
+    /**
+     * @param useDiskShrinker
+     *            The useDiskShrinker to set.
+     */
+    public void setUseDiskShrinker( boolean useDiskShrinker )
+    {
+        UseDiskShrinker = useDiskShrinker;
+    }
+
+    /**
+     * @return Returns the useDiskShrinker.
+     */
+    public boolean isUseDiskShrinker()
+    {
+        return UseDiskShrinker;
+    }
+
+    /**
      * For debugging.
      */
     public String toString()
@@ -203,6 +250,8 @@
         buf.append( "\nTestBeforeInsert [" + isTestBeforeInsert() + "]" );
         buf.append( "\nMaxActive [" + getMaxActive() + "]" );
         buf.append( "\nAllowRemoveAll [" + isAllowRemoveAll() + "]" );
+        buf.append( "\nShrinkerIntervalSeconds [" + getShrinkerIntervalSeconds() + "]" );
+        buf.append( "\nUseDiskShrinker [" + isUseDiskShrinker() + "]" );
         return buf.toString();
     }
 

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManager.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManager.java?rev=387610&r1=387609&r2=387610&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManager.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManager.java Tue Mar 21 12:14:54 2006
@@ -24,6 +24,9 @@
 import org.apache.jcs.auxiliary.AuxiliaryCache;
 import org.apache.jcs.auxiliary.AuxiliaryCacheManager;
 
+import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
+import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
+
 /**
  * This manages instances of the jdbc disk cache. It maintains one for each
  * region. One for all regions would work, but this gives us more detailed stats
@@ -43,7 +46,14 @@
 
     private static JDBCDiskCacheManager instance;
 
-    private static JDBCDiskCacheAttributes defaultCattr;
+    private JDBCDiskCacheAttributes defaultCattr;
+
+    /**
+     * The background disk shrinker, one for all regions.
+     */
+    private ClockDaemon shrinkerDaemon;
+
+    private ShrinkerThread shrinkerThread;
 
     /**
      * Constructor for the HSQLCacheManager object
@@ -129,6 +139,23 @@
             log.debug( "JDBC cache = " + raf );
         }
 
+        // add cache to shrinker.
+        if ( cattr.isUseDiskShrinker() )
+        {
+            if ( shrinkerDaemon == null )
+            {
+                shrinkerDaemon = new ClockDaemon();
+                shrinkerDaemon.setThreadFactory( new MyThreadFactory() );
+            }
+
+            if ( shrinkerThread == null )
+            {
+                shrinkerThread = new ShrinkerThread();
+                shrinkerDaemon.executePeriodically( cattr.getShrinkerIntervalSeconds() * 1000, shrinkerThread, false );
+            }
+            shrinkerThread.addDiskCacheToShrinkList( (JDBCDiskCache) raf );
+        }
+
         return raf;
     }
 
@@ -177,6 +204,30 @@
                     raf.dispose();
                 }
             }
+        }
+    }
+
+    /**
+     * Allows us to set the daemon status on the clockdaemon
+     * 
+     * @author aaronsm
+     * 
+     */
+    class MyThreadFactory
+        implements ThreadFactory
+    {
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see EDU.oswego.cs.dl.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
+         */
+        public Thread newThread( Runnable runner )
+        {
+            Thread t = new Thread( runner );
+            t.setDaemon( true );
+            t.setPriority( Thread.MIN_PRIORITY );
+            return t;
         }
     }
 }

Added: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java?rev=387610&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java Tue Mar 21 12:14:54 2006
@@ -0,0 +1,78 @@
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Calls delete expired on the disk caches. The shrinker is run by a clock
+ * daemon.
+ * 
+ * @author Aaron Smuts
+ * 
+ */
+public class ShrinkerThread
+    implements Runnable
+{
+    private final static Log log = LogFactory.getLog( ShrinkerThread.class );
+
+    private Set shrinkSet = Collections.synchronizedSet( new HashSet() );
+
+    /**
+     * 
+     * @param diskCache
+     */
+    protected ShrinkerThread()
+    {
+        super();
+    }
+
+    /**
+     * Adds a JDBC disk cache to the set of disk cache to shrink.
+     * 
+     * @param diskCache
+     */
+    public void addDiskCacheToShrinkList( JDBCDiskCache diskCache )
+    {
+        // the set will prevent dupes.
+        // we could also just add these to a hasmap by region name
+        // but that might cause a problem if you wanted to use two different
+        // jbdc disk caches for the same region.
+        shrinkSet.add( diskCache );
+    }
+
+    /**
+     * Calls deleteExpired on each item in the set.
+     */
+    public void run()
+    {
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Running JDBC disk cache shrinker.  Number of regions [" + shrinkSet.size() + "]" );
+        }
+
+        Object[] caches = null;
+
+        synchronized ( shrinkSet )
+        {
+            caches = this.shrinkSet.toArray();
+        }
+
+        if ( caches != null )
+        {
+            for ( int i = 0; i < caches.length; i++ )
+            {
+                JDBCDiskCache cache = (JDBCDiskCache) caches[i];
+                int deleted = cache.deleteExpired();
+
+                if ( log.isInfoEnabled() )
+                {
+                    log.info( "Deleted [" + deleted + "] expired for region [" + cache.getCacheName() + "]" );
+                }
+            }
+        }
+    }
+}

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java?rev=387610&r1=387609&r2=387610&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java Tue Mar 21 12:14:54 2006
@@ -343,7 +343,5 @@
             t.setPriority( Thread.MIN_PRIORITY );
             return t;
         }
-
     }
-
 }

Added: jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheShrink.ccf
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheShrink.ccf?rev=387610&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheShrink.ccf (added)
+++ jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheShrink.ccf Tue Mar 21 12:14:54 2006
@@ -0,0 +1,69 @@
+# Cache configuration for the 'TestHSQLDiskCache' test. The memory cache has a
+# a maximum of 100 objects, so objects should get pushed into the disk cache
+
+jcs.default=JDBC
+jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.default.cacheattributes.MaxObjects=100
+jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.default.cacheattributes.UseMemoryShrinker=false
+jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
+jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
+jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
+jcs.default.elementattributes.IsEternal=false
+jcs.default.elementattributes.MaxLifeSeconds=700
+jcs.default.elementattributes.IdleTime=1800
+jcs.default.elementattributes.IsSpool=true
+jcs.default.elementattributes.IsRemote=true
+jcs.default.elementattributes.IsLateral=true
+
+##############################################################
+################## REGIONS ###################################
+jcs.region.expire1Second=JDBC
+jcs.region.expire1Second.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.region.expire1Second.cacheattributes.MaxObjects=0
+jcs.region.expire1Second.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.expire1Second.elementattributes.MaxLifeSeconds=1
+
+jcs.region.expire100Second=JDBC
+jcs.region.expire100Second.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.region.expire100Second.cacheattributes.MaxObjects=0
+jcs.region.expire100Second.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.expire100Second.elementattributes.MaxLifeSeconds=100
+
+jcs.region.eternal=JDBC
+jcs.region.eternal.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.region.eternal.cacheattributes.MaxObjects=0
+jcs.region.eternal.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.eternal.elementattributes.MaxLifeSeconds=1
+jcs.region.eternal.elementattributes.IsEternal=true
+
+##############################################################
+################## AUXILIARY CACHES AVAILABLE ################
+# JDBC disk cache
+jcs.auxiliary.JDBC=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheFactory
+jcs.auxiliary.JDBC.attributes=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes
+jcs.auxiliary.JDBC.attributes.userName=sa
+jcs.auxiliary.JDBC.attributes.password=
+jcs.auxiliary.JDBC.attributes.url=jdbc:hsqldb:target/cache_hsql_db
+jcs.auxiliary.JDBC.attributes.driverClassName=org.hsqldb.jdbcDriver
+jcs.auxiliary.JDBC.attributes.tableName=JCS_STORE_SHRINK
+jcs.auxiliary.JDBC.attributes.testBeforeInsert=false
+jcs.auxiliary.JDBC.attributes.maxActive=15
+jcs.auxiliary.JDBC.attributes.allowRemoveAll=true
+jcs.auxiliary.JDBC.attributes.MaxPurgatorySize=10000000
+jcs.auxiliary.JDBC.attributes.UseDiskShrinker=true
+jcs.auxiliary.JDBC.attributes.ShrinkerIntervalSeconds=1
+jcs.auxiliary.JDBC.attributes.EventQueueType=POOLED
+jcs.auxiliary.JDBC.attributes.EventQueuePoolName=disk_cache_event_queue
+
+
+##############################################################
+################## OPTIONAL THREAD POOL CONFIGURATION #########
+# Disk Cache pool
+thread_pool.disk_cache_event_queue.useBoundary=false
+thread_pool.disk_cache_event_queue.boundarySize=500
+thread_pool.disk_cache_event_queue.maximumPoolSize=15
+thread_pool.disk_cache_event_queue.minimumPoolSize=10
+thread_pool.disk_cache_event_queue.keepAliveTime=3500
+thread_pool.disk_cache_event_queue.whenBlockedPolicy=RUN
+thread_pool.disk_cache_event_queue.startUpSize=10

Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java?rev=387610&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java Tue Mar 21 12:14:54 2006
@@ -0,0 +1,265 @@
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.access.exception.CacheException;
+
+/**
+ * Runs basic tests for the JDBC disk cache.
+ * 
+ * @author Aaron Smuts
+ * 
+ */
+public class JDBCDiskCacheShrinkUnitTest
+    extends TestCase
+{
+
+    /**
+     * Test setup
+     * 
+     * @throws ClassNotFoundException
+     * @throws IllegalAccessException
+     * @throws InstantiationException
+     * @throws SQLException
+     */
+    public void setUp()
+        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+    {
+        JCS.setConfigFilename( "/TestJDBCDiskCacheShrink.ccf" );
+
+        System.setProperty( "hsqldb.cache_scale", "8" );
+
+        String rafroot = "target";
+        Properties p = new Properties();
+        String driver = p.getProperty( "driver", "org.hsqldb.jdbcDriver" );
+        String url = p.getProperty( "url", "jdbc:hsqldb:" );
+        String database = p.getProperty( "database", rafroot + "/cache_hsql_db" );
+        String user = p.getProperty( "user", "sa" );
+        String password = p.getProperty( "password", "" );
+
+        new org.hsqldb.jdbcDriver();
+        Class.forName( driver ).newInstance();
+        Connection cConn = DriverManager.getConnection( url + database, user, password );
+
+        setupTABLE( cConn );
+    }
+
+    /**
+     * Test the basic JDBC disk cache functionality with a hsql backing. Verify
+     * that items configured to expire after 1 second actually expire.
+     * 
+     * @throws Exception
+     */
+    public void testExpireInBackground()
+        throws Exception
+    {
+        String regionExpire = "expire1Second";
+        int items = 200;
+
+        JCS jcsExpire = JCS.getInstance( regionExpire );
+
+        System.out.println( "BEFORE PUT \n" + jcsExpire.getStats() );
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcsExpire.put( i + ":key", regionExpire + " data " + i );
+        }
+
+        System.out.println( jcsExpire.getStats() );
+
+        // the shrinker is supposed to run every second
+        Thread.sleep( 2000 );
+
+        System.out.println( jcsExpire.getStats() );
+
+        // Test that all items have been removed from the cache
+        for ( int i = 0; i <= items; i++ )
+        {
+            assertNull( "Removed key should be null: " + i + ":key", jcsExpire.get( i + ":key" ) );
+        }
+    }
+
+    /**
+     * Verify that those not scheduled to expire do not expire.
+     * 
+     * @throws CacheException
+     * @throws InterruptedException
+     */
+    public void testDidNotExpire()
+        throws CacheException, InterruptedException
+    {
+        String region = "expire100Second";
+        int items = 200;
+
+        JCS jcs = JCS.getInstance( region );
+
+        System.out.println( "BEFORE PUT \n" + jcs.getStats() );
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        System.out.println( jcs.getStats() );
+
+        Thread.sleep( 1000 );
+
+        System.out.println( jcs.getStats() );
+
+        // Test that all items are in cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = (String) jcs.get( i + ":key" );
+
+            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+        }
+
+        // Remove all the items
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.remove( i + ":key" );
+        }
+
+        // Verify removal
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
+        }
+    }
+
+    /**
+     * Verify that eternal trumps max life.
+     * 
+     * @throws CacheException
+     * @throws InterruptedException
+     */
+    public void testDidNotExpireEternal()
+        throws CacheException, InterruptedException
+    {
+        String region = "eternal";
+        int items = 200;
+
+        JCS jcs = JCS.getInstance( region );
+
+        System.out.println( "BEFORE PUT \n" + jcs.getStats() );
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        System.out.println( jcs.getStats() );
+
+        Thread.sleep( 1000 );
+
+        System.out.println( jcs.getStats() );
+
+        // Test that all items are in cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = (String) jcs.get( i + ":key" );
+
+            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+        }
+
+        // Remove all the items
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.remove( i + ":key" );
+        }
+
+        // Verify removal
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
+        }
+    }    
+    
+    /**
+     * SETUP TABLE FOR CACHE
+     * 
+     * @param cConn
+     */
+    void setupTABLE( Connection cConn )
+    {
+        boolean newT = true;
+
+        StringBuffer createSql = new StringBuffer();
+        createSql.append( "CREATE CACHED TABLE JCS_STORE_SHRINK " );
+        createSql.append( "( " );
+        createSql.append( "CACHE_KEY             VARCHAR(250)          NOT NULL, " );
+        createSql.append( "REGION                VARCHAR(250)          NOT NULL, " );
+        createSql.append( "ELEMENT               BINARY, " );
+        createSql.append( "CREATE_TIME           DATE, " );
+        createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
+        createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
+        createSql.append( "IS_ETERNAL            CHAR(1), " );
+        createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
+        createSql.append( ");" );
+
+        Statement sStatement = null;
+        try
+        {
+            sStatement = cConn.createStatement();
+        }
+        catch ( SQLException e )
+        {
+            e.printStackTrace();
+        }
+
+        try
+        {
+            sStatement.executeQuery( createSql.toString() );
+            sStatement.close();
+        }
+        catch ( SQLException e )
+        {
+            if ( e.toString().indexOf( "already exists" ) != -1 )
+            {
+                newT = false;
+            }
+            else
+            {
+                // TODO figure out if it exists prior to trying to create it.
+                // log.error( "Problem creating table.", e );
+                e.printStackTrace();
+            }
+        }
+
+        String setupData[] = { "create index iKEY on JCS_STORE_SHRINK (CACHE_KEY, REGION)" };
+
+        if ( newT )
+        {
+            for ( int i = 1; i < setupData.length; i++ )
+            {
+                try
+                {
+                    sStatement.executeQuery( setupData[i] );
+                }
+                catch ( SQLException e )
+                {
+                    System.out.println( "Exception: " + e );
+                }
+            }
+        } // end ifnew
+    }
+}

Modified: jakarta/jcs/trunk/xdocs/JDBCDiskCacheProperties.xml
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/xdocs/JDBCDiskCacheProperties.xml?rev=387610&r1=387609&r2=387610&view=diff
==============================================================================
--- jakarta/jcs/trunk/xdocs/JDBCDiskCacheProperties.xml (original)
+++ jakarta/jcs/trunk/xdocs/JDBCDiskCacheProperties.xml Tue Mar 21 12:14:54 2006
@@ -45,9 +45,7 @@
 
 					<tr>
 						<td>database</td>
-						<td>
-							This is appended to the url.
-						</td>
+						<td>This is appended to the url.</td>
 						<td>Y</td>
 						<td></td>
 					</tr>
@@ -103,6 +101,23 @@
 						<td>true</td>
 					</tr>
 
+					<tr>
+						<td>UseDiskShrinker</td>
+						<td>
+							Should the disk cache try to delete expired
+							items from the database.
+						</td>
+						<td>N</td>
+						<td>true</td>
+					</tr>
+
+					<tr>
+						<td>ShrinkerIntervalSeconds</td>
+						<td>How often should the disk shrinker run.</td>
+						<td>N</td>
+						<td>300</td>
+					</tr>
+
 				</table>
 			</subsection>
 
@@ -124,6 +139,8 @@
 jcs.auxiliary.JDBC.attributes.maxActive=15
 jcs.auxiliary.JDBC.attributes.allowRemoveAll=true
 jcs.auxiliary.JDBC.attributes.MaxPurgatorySize=10000000
+jcs.auxiliary.JDBC.attributes.UseDiskShrinker=true
+jcs.auxiliary.JDBC.attributes.ShrinkerIntervalSeconds=300
         ]]>
 				</source>
 			</subsection>
@@ -191,6 +208,8 @@
 jcs.auxiliary.JDBC.attributes.maxActive=15
 jcs.auxiliary.JDBC.attributes.allowRemoveAll=true
 jcs.auxiliary.JDBC.attributes.MaxPurgatorySize=10000000
+jcs.auxiliary.JDBC.attributes.UseDiskShrinker=true
+jcs.auxiliary.JDBC.attributes.ShrinkerIntervalSeconds=300
 jcs.auxiliary.JDBC.attributes.EventQueueType=POOLED
 jcs.auxiliary.JDBC.attributes.EventQueuePoolName=disk_cache_event_queueue
 
@@ -207,7 +226,7 @@
         ]]>
 				</source>
 			</subsection>
-			
+
 		</section>
 	</body>
 </document>



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org