org.apache.velocity.runtime.resource
public class: ResourceCacheImpl [javadoc |
source]
java.lang.Object
org.apache.velocity.runtime.resource.ResourceCacheImpl
All Implemented Interfaces:
ResourceCache
Default implementation of the resource cache for the default
ResourceManager. The cache uses a
least recently used (LRU)
algorithm, with a maximum size specified via the
resource.manager.cache.size property (idenfied by the
org.apache.velocity.runtime.RuntimeConstants#RESOURCE_MANAGER_DEFAULTCACHE_SIZE
constant). This property get be set to
0 or less for
a greedy, unbounded cache (the behavior from pre-v1.5).
- author:
< - a href="mailto:geirm@apache.org">Geir Magnusson Jr.
- author:
< - a href="mailto:dlr@finemaltcoding.com">Daniel Rall
- version:
$ - Id: ResourceCacheImpl.java 463298 2006-10-12 16:10:32Z henning $
| Field Summary |
|---|
| protected Map | cache | Cache storage, assumed to be thread-safe. |
| protected RuntimeServices | rsvc | Runtime services, generally initialized by the
initialize() method. |
| Method from org.apache.velocity.runtime.resource.ResourceCacheImpl Detail: |
public Iterator enumerateKeys() {
return cache.keySet().iterator();
}
|
public Resource get(Object key) {
return (Resource) cache.get( key );
}
|
public void initialize(RuntimeServices rs) {
rsvc = rs;
int maxSize =
rsvc.getInt(RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE, 89);
if (maxSize > 0)
{
// Create a whole new Map here to avoid hanging on to a
// handle to the unsynch'd LRUMap for our lifetime.
Map lruCache = Collections.synchronizedMap(new LRUMap(maxSize));
lruCache.putAll(cache);
cache = lruCache;
}
rsvc.getLog().debug("ResourceCache: initialized ("+this.getClass()+')");
}
|
public Resource put(Object key,
Resource value) {
return (Resource) cache.put( key, value );
}
|
public Resource remove(Object key) {
return (Resource) cache.remove( key );
}
|