velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Rall <>
Subject Re: Caching / OutOfMemoryException
Date Thu, 12 Jan 2006 00:56:47 GMT

On Tue, 10 Jan 2006, Fredrik Andersson wrote:

> I'll try the resource.manager.defaultcache setting. I seem to remember that
> I stumbled upon a forum thread or mailinglist some weeks ago arguing that
> this setting was limitless unless you set it explicitly.

Even not setting this property should create a (non-greedy) LRUMap by

public class ResourceCacheImpl implements ResourceCache
    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));
            cache = lruCache;
        rsvc.getLog().info("ResourceCache: initialized ("+this.getClass()+')');

> This setting isn't very documented, by the way! I'll just browse the
> source and see what it does.

Here's what I found:

--- snip ---
resource.manager.cache.class Declares the class to be used for
resource caching. The current default is
org.apache.velocity.runtime.resource.ResourceCacheImpl which uses a
LRU Map to prevent data from being held forever. You can set the size
of the LRU Map using the parameter
resource.manager.defaultcache.size. The dafault value of the default
cache size is currently 89.

resource.manager.defaultcache.size Sets the size of the default
implementation of the resource manager resource cache.
--- snip ---

Fredrik, how do you recommend we change that to improve things?

Daniel Rall

View raw message