org.apache.velocity.runtime.resource
Class ResourceCacheImpl

java.lang.Object
  extended by org.apache.velocity.runtime.resource.ResourceCacheImpl
All Implemented Interfaces:
ResourceCache

public class ResourceCacheImpl
extends Object
implements 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 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).

Version:
$Id: ResourceCacheImpl.java 191743 2005-06-21 23:22:20Z dlr $
Author:
Geir Magnusson Jr., Daniel Rall

Field Summary
protected  Map cache
          Cache storage, assumed to be thread-safe.
protected  RuntimeServices rsvc
          Runtime services, generally initialized by the initialize() method.
 
Constructor Summary
ResourceCacheImpl()
           
 
Method Summary
 Iterator enumerateKeys()
          returns an Iterator of Keys in the cache
 Resource get(Object key)
          retrieves a Resource from the cache
 void initialize(RuntimeServices rs)
          initializes the ResourceCache.
 Resource put(Object key, Resource value)
          stores a Resource in the cache
 Resource remove(Object key)
          removes a Resource from the cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected Map cache
Cache storage, assumed to be thread-safe.


rsvc

protected RuntimeServices rsvc
Runtime services, generally initialized by the initialize() method.

Constructor Detail

ResourceCacheImpl

public ResourceCacheImpl()
Method Detail

initialize

public void initialize(RuntimeServices rs)
Description copied from interface: ResourceCache
initializes the ResourceCache. Will be called before any utilization

Specified by:
initialize in interface ResourceCache
Parameters:
rs - RuntimeServices to use for logging, etc

get

public Resource get(Object key)
Description copied from interface: ResourceCache
retrieves a Resource from the cache

Specified by:
get in interface ResourceCache
Parameters:
key - key for Resource to be retrieved
Returns:
Resource specified or null if not found

put

public Resource put(Object key,
                    Resource value)
Description copied from interface: ResourceCache
stores a Resource in the cache

Specified by:
put in interface ResourceCache
Parameters:
key - key to associate with the Resource
value - Resource to be stored
Returns:
existing Resource stored under this key, or null if none

remove

public Resource remove(Object key)
Description copied from interface: ResourceCache
removes a Resource from the cache

Specified by:
remove in interface ResourceCache
Parameters:
key - resource to be removed
Returns:
Resource stored under key

enumerateKeys

public Iterator enumerateKeys()
Description copied from interface: ResourceCache
returns an Iterator of Keys in the cache

Specified by:
enumerateKeys in interface ResourceCache


Copyright © 2002 Apache Software Foundation. All Rights Reserved.