jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asm...@apache.org
Subject cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed IndexedDiskCacheAttributes.java IndexedDiskCache.java
Date Mon, 10 May 2004 01:16:16 GMT
asmuts      2004/05/09 18:16:16

  Modified:    src/java/org/apache/jcs/auxiliary/disk/indexed
                        IndexedDiskCacheAttributes.java
                        IndexedDiskCache.java
  Log:
  Added disk key size memory management.  Ca set the max number of disk keys in a parameter.
  
  Revision  Changes    Path
  1.7       +22 -0     jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java
  
  Index: IndexedDiskCacheAttributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- IndexedDiskCacheAttributes.java	15 Apr 2004 19:22:57 -0000	1.6
  +++ IndexedDiskCacheAttributes.java	10 May 2004 01:16:16 -0000	1.7
  @@ -32,6 +32,8 @@
   
       private String diskPath;
   
  +    // default to 500000
  +    private int maxKeySize = 500000;
   
       /**
        * Constructor for the DiskCacheAttributes object
  @@ -106,6 +108,26 @@
           this.name = name;
       }
   
  +    /**
  +     * Gets the maxKeySize attribute of the DiskCacheAttributes object
  +     *
  +     * @return The maxKeySize value
  +     */
  +    public int getMaxKeySize()
  +    {
  +        return this.maxKeySize;
  +    }
  +
  +
  +    /**
  +     * Sets the maxKeySize attribute of the DiskCacheAttributes object
  +     *
  +     * @param name The new maxKeySize value
  +     */
  +    public void setMaxKeySize( int maxKeySize )
  +    {
  +        this.maxKeySize = maxKeySize;
  +    }
   
       /**
        * Description of the Method
  
  
  
  1.11      +34 -14    jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
  
  Index: IndexedDiskCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- IndexedDiskCache.java	15 Apr 2004 19:22:57 -0000	1.10
  +++ IndexedDiskCache.java	10 May 2004 01:16:16 -0000	1.11
  @@ -31,6 +31,7 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.jcs.auxiliary.disk.AbstractDiskCache;
  +import org.apache.jcs.auxiliary.disk.LRUMapJCS;
   import org.apache.jcs.engine.CacheConstants;
   import org.apache.jcs.engine.CacheElement;
   import org.apache.jcs.engine.behavior.ICacheElement;
  @@ -51,10 +52,13 @@
       private String fileName;
       private IndexedDisk dataFile;
       private IndexedDisk keyFile;
  -    private HashMap keyHash;
  +    private LRUMapJCS keyHash;
  +    private int maxKeySize;
   
       private File rafDir;
   
  +
  +
       IndexedDiskCacheAttributes cattr;
   
       /**
  @@ -74,6 +78,7 @@
   
           String cacheName = cattr.getCacheName();
           String rootDirName = cattr.getDiskPath();
  +        maxKeySize = cattr.getMaxKeySize();
   
           this.cattr = cattr;
   
  @@ -110,7 +115,7 @@
   
               else
               {
  -                keyHash = new HashMap();
  +                keyHash = new LRUMapJCS( maxKeySize );
   
                   if ( dataFile.length() > 0 )
                   {
  @@ -144,17 +149,25 @@
   
           try
           {
  -            keyHash = ( HashMap ) keyFile.readObject( 0 );
  +            keyHash = ( LRUMapJCS ) keyFile.readObject( 0 );
   
               if ( keyHash == null )
               {
  -                keyHash = new HashMap();
  +                keyHash = new LRUMapJCS( maxKeySize );
               }
  -
  -            if ( log.isInfoEnabled() )
  +            else
               {
  -               log.info( "Loaded keys from: " + fileName +
  -                    ", key count: " + keyHash.size() );
  +                if ( log.isInfoEnabled() )
  +                {
  +                  log.info( "Loaded keys from: " + fileName +
  +                          ", key count: " + keyHash.size() );
  +                }
  +
  +                keyHash.setMaximumSize( maxKeySize );
  +                if ( log.isInfoEnabled() )
  +                {
  +                  log.info( "Reset maxKeySize to: '" + maxKeySize + "'" );
  +                }
               }
   
               if ( log.isDebugEnabled() )
  @@ -501,7 +514,7 @@
               keyFile =
                   new IndexedDisk( new File( rafDir, fileName + ".key" ) );
   
  -            keyHash = new HashMap();
  +            keyHash = new LRUMapJCS( this.maxKeySize );
           }
           catch ( Exception e )
           {
  @@ -579,7 +592,7 @@
           {
               // Migrate from keyHash to keyHshTemp in memory,
               // and from dataFile to dataFileTemp on disk.
  -            HashMap keyHashTemp = new HashMap();
  +            LRUMapJCS keyHashTemp = new LRUMapJCS( this.maxKeySize );
   
               IndexedDisk dataFileTemp =
                   new IndexedDisk( new File( rafDir, fileName + "Temp.data" ) );
  @@ -589,11 +602,16 @@
                   log.info( "Optomizing file keyHash.size()=" + keyHash.size() );
               }
   
  -            Iterator itr = keyHash.keySet().iterator();
  +            //Iterator itr = keyHash.keySet().iterator();
   
  -            while ( itr.hasNext() )
  +            Object[] keys = keyHash.keySet().toArray();
  +            int len = keys.length;
  +
  +            //while ( itr.hasNext() )
  +            for ( int i = 0; i < len; i++ )
               {
  -                Serializable key = ( Serializable ) itr.next();
  +                //Serializable key = ( Serializable ) itr.next();
  +                Serializable key = ( Serializable ) keys[i];
   
                   CacheElement tempDe = ( CacheElement ) readElement( key );
                   try
  @@ -698,5 +716,7 @@
                          ", pos: " + ded.pos );
           }
       }
  +
   }
  +
   
  
  
  

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


Mime
View raw message