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/30 12:36:10 UTC
cvs commit: jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft SoftRefCacheSafe.java SoftRefFileCacheSafe.java
hchar 2005/01/30 03:36:10
Modified: sandbox/yajcache/src/org/apache/jcs/yajcache/core
CacheType.java SafeCacheManager.java
Added: sandbox/yajcache/src/org/apache/jcs/yajcache/core
SafeCacheWrapper.java
Removed: sandbox/yajcache/src/org/apache/jcs/yajcache/soft
SoftRefCacheSafe.java SoftRefFileCacheSafe.java
Log:
replace all safe caches with SafeCacheWrapper
Revision Changes Path
1.3 +4 -6 jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheType.java
Index: CacheType.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheType.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CacheType.java 29 Jan 2005 12:37:00 -0000 1.2
+++ CacheType.java 30 Jan 2005 11:36:10 -0000 1.3
@@ -17,9 +17,7 @@
package org.apache.jcs.yajcache.core;
import org.apache.jcs.yajcache.soft.SoftRefCache;
-import org.apache.jcs.yajcache.soft.SoftRefCacheSafe;
import org.apache.jcs.yajcache.soft.SoftRefFileCache;
-import org.apache.jcs.yajcache.soft.SoftRefFileCacheSafe;
import org.apache.jcs.yajcache.lang.annotation.*;
@@ -40,11 +38,11 @@
case SOFT_REFERENCE:
return new SoftRefCache<V>(name, valueType);
case SOFT_REFERENCE_SAFE:
- return new SoftRefCacheSafe<V>(name, valueType);
+ return new SafeCacheWrapper<V>(new SoftRefCache<V>(name, valueType));
case SOFT_REFERENCE_FILE:
return new SoftRefFileCache<V>(name, valueType);
case SOFT_REFERENCE_FILE_SAFE:
- return new SoftRefFileCacheSafe<V>(name, valueType);
+ return new SafeCacheWrapper<V>(new SoftRefFileCache<V>(name, valueType));
}
throw new AssertionError(this);
}
@@ -52,9 +50,9 @@
{
switch(this) {
case SOFT_REFERENCE_SAFE:
- return new SoftRefCacheSafe<V>(name, valueType);
+ return new SafeCacheWrapper<V>(new SoftRefCache<V>(name, valueType));
case SOFT_REFERENCE_FILE_SAFE:
- return new SoftRefFileCacheSafe<V>(name, valueType);
+ return new SafeCacheWrapper<V>(new SoftRefFileCache<V>(name, valueType));
}
throw new UnsupportedOperationException("");
}
1.6 +1 -3 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SafeCacheManager.java 29 Jan 2005 12:37:00 -0000 1.5
+++ SafeCacheManager.java 30 Jan 2005 11:36:10 -0000 1.6
@@ -19,9 +19,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.jcs.yajcache.lang.annotation.*;
-import org.apache.jcs.yajcache.config.PerCacheConfig;
-import org.apache.jcs.yajcache.file.CacheFileManager;
-import org.apache.jcs.yajcache.soft.SoftRefFileCacheSafe;
+
/**
* @author Hanson Char
1.1 jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/SafeCacheWrapper.java
Index: SafeCacheWrapper.java
===================================================================
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jcs.yajcache.core;
import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.jcs.yajcache.util.BeanUtils;
import org.apache.jcs.yajcache.util.SerializeUtils;
import org.apache.jcs.yajcache.lang.annotation.*;
/**
* Safe Cache as a wrapper of an underlying cache.
*
* @author Hanson Char
*/
@CopyRightApache
public class SafeCacheWrapper<V> implements ICacheSafe<V>
{
/** Underlying cache. */
private final @NonNullable ICache<V> cache;
/**
* Constructs a safe cache by wrapping an underlying cache.
* @param cache underlying cache.
*/
public SafeCacheWrapper(@NonNullable ICache<V> cache)
{
this.cache = cache;
}
// ICache implementation by delegating to the underlying cache.
public String getName() {
return this.cache.getName();
}
public Class<V> getValueType() {
return this.cache.getValueType();
}
public V get(String key) {
return this.cache.get(key);
}
public int size() {
return this.cache.size();
}
public boolean isEmpty() {
return this.cache.isEmpty();
}
public boolean containsKey(Object key) {
return this.cache.containsKey(key);
}
public boolean containsValue(Object value) {
return this.cache.containsValue(value);
}
public V get(Object key) {
return this.cache.get(key);
}
public V put(String key, V value) {
return this.cache.put(key, value);
}
public V remove(Object key) {
return this.cache.remove(key);
}
public void clear() {
this.cache.clear();
}
public Set<String> keySet() {
return this.cache.keySet();
}
public Collection<V> values() {
return this.cache.values();
}
public Set<Map.Entry<String, V>> entrySet() {
return this.cache.entrySet();
}
// ICacheSafe implementation
public V getCopy(@NonNullable String key) {
V val = this.cache.get(key);
return this.dup(val);
}
public V putCopy(@NonNullable String key, @NonNullable V value) {
return this.cache.put(key, this.dup(value));
}
public void putAll(@NonNullable Map<? extends String, ? extends V> map) {
for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
this.cache.put(e.getKey(), e.getValue());
}
public void putAllCopies(@NonNullable Map<? extends String, ? extends V> map) {
for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
this.cache.put(e.getKey(), this.dup(e.getValue()));
}
public V getBeanCopy(@NonNullable String key) {
V val = this.cache.get(key);
return BeanUtils.inst.cloneDeep(val);
}
public V putBeanCopy(@NonNullable String key, @NonNullable V value) {
return this.cache.put(key, BeanUtils.inst.cloneDeep(value));
}
public void putAllBeanCopies(@NonNullable Map<? extends String, ? extends V> map) {
for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
this.cache.put(e.getKey(), BeanUtils.inst.cloneDeep(e.getValue()));
}
public V getBeanClone(@NonNullable String key) {
V val = this.cache.get(key);
return BeanUtils.inst.cloneShallow(val);
}
public V putBeanClone(@NonNullable String key, @NonNullable V value) {
return this.cache.put(key, BeanUtils.inst.cloneShallow(value));
}
public void putAllBeanClones(@NonNullable Map<? extends String, ? extends V> map) {
for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
this.cache.put(e.getKey(), BeanUtils.inst.cloneShallow(e.getValue()));
}
private V dup(V val) {
if (val instanceof Serializable) {
return (V)SerializeUtils.inst.dup((Serializable)val);
}
return val;
}
@Override public String toString() {
return new ToStringBuilder(this)
.append(this.cache)
.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org