jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asm...@apache.org
Subject svn commit: r393886 - in /jakarta/jcs/trunk/src: java/org/apache/jcs/auxiliary/disk/jdbc/ java/org/apache/jcs/auxiliary/disk/jdbc/hsql/ test/org/apache/jcs/auxiliary/disk/jdbc/
Date Thu, 13 Apr 2006 18:55:36 GMT
Author: asmuts
Date: Thu Apr 13 11:55:33 2006
New Revision: 393886

URL: http://svn.apache.org/viewcvs?rev=393886&view=rev
Log:
Added an expire time to the jdbc disk cache table struture.  Without it
a full table scan is necessary in order to expire elements.  With it, you can scale 
into the millions of records.

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/hsql/HSQLDiskCacheFactory.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java

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=393886&r1=393885&r2=393886&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 Thu Apr
13 11:55:33 2006
@@ -54,24 +54,30 @@
  * 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,
+ *                 SYSTEM_EXPIRE_TIME_SECONDS BIGINT,
+ *                 IS_ETERNAL                 CHAR(1),
+ *                 PRIMARY KEY (CACHE_KEY, REGION)
+ *                 );
  * </pre>
  * 
  * 
  * The cleanup thread will delete non eternal items where (now - create time) >
  * max life seconds * 1000
+ * <p>
+ * To speed up the deletion the SYSTEM_EXPIRE_TIME_SECONDS is used instead. It
+ * is recommended that an index be created on this column is you will have over
+ * a million records.
+ * 
  * 
  * @author Aaron Smuts
  * 
@@ -239,7 +245,8 @@
                 {
                     String sqlI = "insert into "
                         + getJdbcDiskCacheAttributes().getTableName()
-                        + " (CACHE_KEY, REGION, ELEMENT, MAX_LIFE_SECONDS, IS_ETERNAL, CREATE_TIME,
CREATE_TIME_SECONDS) values (?, ?, ?, ?, ?, ?, ?)";
+                        + " (CACHE_KEY, REGION, ELEMENT, MAX_LIFE_SECONDS, IS_ETERNAL, CREATE_TIME,
CREATE_TIME_SECONDS, SYSTEM_EXPIRE_TIME_SECONDS) "
+                        + " values (?, ?, ?, ?, ?, ?, ?, ?)";
 
                     PreparedStatement psInsert = con.prepareStatement( sqlI );
                     psInsert.setString( 1, (String) ce.getKey() );
@@ -256,9 +263,13 @@
                     }
                     Date createTime = new Date( ce.getElementAttributes().getCreateTime()
);
                     psInsert.setDate( 6, createTime );
+
                     long now = System.currentTimeMillis() / 1000;
                     psInsert.setLong( 7, now );
 
+                    long expireTime = now + ce.getElementAttributes().getMaxLifeSeconds();
+                    psInsert.setLong( 8, expireTime );
+
                     psInsert.execute();
                     psInsert.close();
                 }
@@ -290,11 +301,22 @@
                 try
                 {
                     sqlU = "update " + getJdbcDiskCacheAttributes().getTableName()
-                        + " set ELEMENT  = ? where CACHE_KEY = ? and REGION = ? ";
+                        + " set ELEMENT  = ?, CREATE_TIME = ?, CREATE_TIME_SECONDS = ?, "
+                        + " SYSTEM_EXPIRE_TIME_SECONDS = ? " + " where CACHE_KEY = ? and
REGION = ?";
                     PreparedStatement psUpdate = con.prepareStatement( sqlU );
                     psUpdate.setBytes( 1, element );
-                    psUpdate.setString( 2, (String) ce.getKey() );
-                    psUpdate.setString( 3, this.getCacheName() );
+
+                    Date createTime = new Date( ce.getElementAttributes().getCreateTime()
);
+                    psUpdate.setDate( 2, createTime );
+
+                    long now = System.currentTimeMillis() / 1000;
+                    psUpdate.setLong( 3, now );
+
+                    long expireTime = now + ce.getElementAttributes().getMaxLifeSeconds();
+                    psUpdate.setLong( 4, expireTime );
+
+                    psUpdate.setString( 5, (String) ce.getKey() );
+                    psUpdate.setString( 6, this.getCacheName() );
                     psUpdate.execute();
                     psUpdate.close();
 
@@ -646,8 +668,16 @@
         try
         {
             long now = System.currentTimeMillis() / 1000;
+
+            // This is to slow when we push over a million records
+            // String sql = "delete from " +
+            // getJdbcDiskCacheAttributes().getTableName() + " where REGION = '"
+            // + this.getCacheName() + "' and IS_ETERNAL = 'F' and (" + now
+            // + " - CREATE_TIME_SECONDS) > MAX_LIFE_SECONDS";
+
             String sql = "delete from " + getJdbcDiskCacheAttributes().getTableName() + "
where REGION = '"
-                + this.getCacheName() + "' and IS_ETERNAL = 'F' and (" + now + " - CREATE_TIME_SECONDS)
> MAX_LIFE_SECONDS";
+                + this.getCacheName() + "' and IS_ETERNAL = 'F' and " + now + " > SYSTEM_EXPIRE_TIME_SECONDS";
+
             Connection con = DriverManager.getConnection( getPoolUrl() );
             Statement sStatement = null;
             try
@@ -848,9 +878,9 @@
         ObjectPool connectionPool = new GenericObjectPool( null, maxActive );
 
         // TODO make configurable
-        // By dfault the size is 8!!!!!!!  
-        ((GenericObjectPool)connectionPool).setMaxIdle( -1 );
-        
+        // By dfault the size is 8!!!!!!!
+        ( (GenericObjectPool) connectionPool ).setMaxIdle( -1 );
+
         // Next, we'll create a ConnectionFactory that the
         // pool will use to create Connections.
         // We'll use the DriverManagerConnectionFactory,

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java?rev=393886&r1=393885&r2=393886&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
Thu Apr 13 11:55:33 2006
@@ -165,6 +165,7 @@
         createSql.append( "CREATE_TIME           DATE, " );
         createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
         createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
+        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );        
         createSql.append( "IS_ETERNAL            CHAR(1), " );
         createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
         createSql.append( ");" );
@@ -196,6 +197,7 @@
             }
         }
 
+        //TODO create an index on SYSTEM_EXPIRE_TIME_SECONDS
         String setupData[] = { "create index iKEY on " + tableName + " (CACHE_KEY, REGION)"
};
 
         if ( newT )

Modified: 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=393886&r1=393885&r2=393886&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java
Thu Apr 13 11:55:33 2006
@@ -212,6 +212,7 @@
         createSql.append( "CREATE_TIME           DATE, " );
         createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
         createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
+        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );                
         createSql.append( "IS_ETERNAL            CHAR(1), " );
         createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
         createSql.append( ");" );

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java?rev=393886&r1=393885&r2=393886&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java
Thu Apr 13 11:55:33 2006
@@ -128,6 +128,7 @@
         createSql.append( "CREATE_TIME           DATE, " );
         createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
         createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
+        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );        
         createSql.append( "IS_ETERNAL            CHAR(1), " );
         createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
         createSql.append( ");" );



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


Mime
View raw message