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 hc...@apache.org on 2005/01/29 11:16:38 UTC

cvs commit: jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core CacheManager.java SafeCacheManager.java

hchar       2005/01/29 02:16:38

  Modified:    sandbox/yajcache/src/org/apache/jcs/yajcache/core
                        CacheManager.java SafeCacheManager.java
  Log:
  support specifying cache type
  
  Revision  Changes    Path
  1.4       +20 -8     jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheManager.java
  
  Index: CacheManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CacheManager.java	27 Jan 2005 10:56:14 -0000	1.3
  +++ CacheManager.java	29 Jan 2005 10:16:38 -0000	1.4
  @@ -33,6 +33,7 @@
       // Cache name to Cache mapping.
       private final ConcurrentMap<String,ICache<?>> map = 
                   new ConcurrentHashMap<String, ICache<?>>();
  +    private final CacheType DEFAULT_CACHE_TYPE = CacheType.SOFT_REFERENCE_FILE;
       /** 
        * Returns the cache for the specified name and value type;  
        * Creates the cache if necessary.
  @@ -41,14 +42,22 @@
        * incompatible value type.
        */
   //    @SuppressWarnings({"unchecked"})
  -    public @NonNullable <V> ICache<V> getCache(@NonNullable String name, @NonNullable Class<V> valueType)
  +    public @NonNullable <V> ICache<V> getCache(
  +            @NonNullable String name, 
  +            @NonNullable Class<V> valueType)
  +    {
  +        return this.getCache(DEFAULT_CACHE_TYPE, name, valueType);
  +    }
  +    public @NonNullable <V> ICache<V> getCache(
  +            @NonNullable CacheType cacheType, 
  +            @NonNullable String name, 
  +            @NonNullable Class<V> valueType)
       {
           ICache c = this.map.get(name);
                  
           if (c == null)
  -            c = this.createCache(name, valueType);
  -        else
  -            CacheManagerUtils.inst.checkValueType(c, valueType);
  +            return this.createCache(cacheType, name, valueType);
  +        CacheManagerUtils.inst.checkValueType(c, valueType);
           return c;
       }
       /** 
  @@ -76,10 +85,13 @@
        */
   //    @SuppressWarnings({"unchecked"})
       private @NonNullable <V> ICache<V> createCache(
  -            @NonNullable String name, @NonNullable Class<V> valueType) 
  +            @NonNullable CacheType cacheType,
  +            @NonNullable String name, 
  +            @NonNullable Class<V> valueType)
       {
  -        SoftRefFileCache<V> c = new SoftRefFileCache<V>(name, valueType, new PerCacheConfig());
  -        c.addCacheChangeListener(new CacheFileManager<V>(c));
  +        ICache<V> c = cacheType.createCache(name, valueType);
  +//        SoftRefFileCache<V> c = new SoftRefFileCache<V>(name, valueType);
  +//        c.addCacheChangeListener(new CacheFileManager<V>(c));
           ICache old = this.map.putIfAbsent(name, c);
   
           if (old != null) {
  @@ -93,6 +105,6 @@
       @TestOnly("Used solely to simluate a race condition during cache creation ")
       @NonNullable <V> ICache<V> testCreateCacheRaceCondition(@NonNullable String name, @NonNullable Class<V> valueType) 
       {
  -        return this.createCache(name, valueType);
  +        return this.createCache(DEFAULT_CACHE_TYPE, name, valueType);
       }
   }
  
  
  
  1.4       +18 -9     jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/SafeCacheManager.java
  
  Index: SafeCacheManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/SafeCacheManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SafeCacheManager.java	27 Jan 2005 10:56:14 -0000	1.3
  +++ SafeCacheManager.java	29 Jan 2005 10:16:38 -0000	1.4
  @@ -33,6 +33,7 @@
       // Cache name to Cache mapping.
       private final @NonNullable ConcurrentMap<String,ICacheSafe> map = 
               new ConcurrentHashMap<String, ICacheSafe>();
  +    private final CacheType DEFAULT_CACHE_TYPE = CacheType.SOFT_REFERENCE_FILE_SAFE;
       /** 
        * Returns the cache for the specified name and value type;  
        * Creates the cache if necessary.
  @@ -41,14 +42,21 @@
        * incompatible value type.
        */
       public @NonNullable <V> ICacheSafe<V> getCache(
  -            @NonNullable String name, @NonNullable Class<V> valueType)
  +            @NonNullable String name, 
  +            @NonNullable Class<V> valueType)
  +    {
  +        return this.getCache(DEFAULT_CACHE_TYPE, name, valueType);
  +    }
  +    public @NonNullable <V> ICacheSafe<V> getCache(
  +            @NonNullable CacheType cacheType, 
  +            @NonNullable String name, 
  +            @NonNullable Class<V> valueType)
       {
           ICacheSafe c = this.map.get(name);
                  
           if (c == null)
  -            c = this.createCache(name, valueType);
  -        else
  -            CacheManagerUtils.inst.checkValueType(c, valueType);
  +            return this.createCache(cacheType, name, valueType);
  +        CacheManagerUtils.inst.checkValueType(c, valueType);
           return c;
       }
       /** 
  @@ -75,11 +83,12 @@
        * an existing cache created earlier by another thread.
        */
       private @NonNullable <V> ICacheSafe<V> createCache(
  -            @NonNullable String name, @NonNullable Class<V> valueType) 
  +            @NonNullable CacheType cacheType,
  +            @NonNullable String name, 
  +            @NonNullable Class<V> valueType) 
       {
  -        SoftRefFileCacheSafe<V> c = 
  -                new SoftRefFileCacheSafe<V>(name, valueType, new PerCacheConfig());
  -        c.addCacheChangeListener(new CacheFileManager<V>(c));
  +        ICacheSafe<V> c = cacheType.createSafeCache(name, valueType);
  +//        c.addCacheChangeListener(new CacheFileManager<V>(c));
           ICacheSafe old = this.map.putIfAbsent(name, c);
   
           if (old != null) {
  @@ -94,6 +103,6 @@
       @NonNullable <V> ICacheSafe<V> testCreateCacheRaceCondition(
               @NonNullable String name, @NonNullable Class<V> valueType)
       {
  -        return this.createCache(name, valueType);
  +        return this.createCache(DEFAULT_CACHE_TYPE, name, valueType);
       }
   }
  
  
  

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