View Javadoc

1   package org.apache.jcs.auxiliary.disk.file;
2   
3   import java.io.Serializable;
4   
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
8   import org.apache.jcs.auxiliary.AuxiliaryCacheFactory;
9   import org.apache.jcs.engine.behavior.ICompositeCacheManager;
10  import org.apache.jcs.engine.behavior.IElementSerializer;
11  import org.apache.jcs.engine.logging.behavior.ICacheEventLogger;
12  
13  /** Create Disk File Caches */
14  public class FileDiskCacheFactory
15      implements AuxiliaryCacheFactory
16  {
17      /** The logger. */
18      private final static Log log = LogFactory.getLog( FileDiskCacheFactory.class );
19  
20      /** The auxiliary name. */
21      private String name;
22  
23      /** The manager used by this factory instance */
24      private FileDiskCacheManager diskFileCacheManager;
25  
26      /**
27       * Creates a manager if we don't have one, and then uses the manager to create the cache. The
28       * same factory will be called multiple times by the composite cache to create a cache for each
29       * region.
30       * <p>
31       * @param attr config
32       * @param cacheMgr the manager to use if needed
33       * @param cacheEventLogger the event logger
34       * @param elementSerializer the serializer
35       * @return AuxiliaryCache
36       */
37      public <K extends Serializable, V extends Serializable> FileDiskCache<K, V> createCache(
38              AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr,
39             ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
40      {
41          FileDiskCacheAttributes idfca = (FileDiskCacheAttributes) attr;
42          if ( log.isDebugEnabled() )
43          {
44              log.debug( "Creating DiskFileCache for attributes = " + idfca );
45          }
46          synchronized( this )
47          {
48              if ( diskFileCacheManager == null )
49              {
50                  if ( log.isDebugEnabled() )
51                  {
52                      log.debug( "Creating DiskFileCacheManager" );
53                  }
54                  diskFileCacheManager = new FileDiskCacheManager( idfca, cacheEventLogger, elementSerializer );
55              }
56              return diskFileCacheManager.getCache( idfca );
57          }
58      }
59  
60      /**
61       * Gets the name attribute of the DiskCacheFactory object
62       * <p>
63       * @return The name value
64       */
65      public String getName()
66      {
67          return this.name;
68      }
69  
70      /**
71       * Sets the name attribute of the DiskCacheFactory object
72       * <p>
73       * @param name The new name value
74       */
75      public void setName( String name )
76      {
77          this.name = name;
78      }
79  }