Example usage for org.apache.commons.collections LRUMap setMaximumSize

List of usage examples for org.apache.commons.collections LRUMap setMaximumSize

Introduction

In this page you can find the example usage for org.apache.commons.collections LRUMap setMaximumSize.

Prototype

public void setMaximumSize(int maximumSize) 

Source Link

Document

Setter for property maximumSize.

Usage

From source file:net.sf.jrf.domain.PersistentObjectCache.java

/**
 *  Sets the maximum size of the cache. A size of zero denotes no cache.
 *  This method may be used to increase the size of an existing cache. If
 *  'cacheAll' is set, calling this method will clear the cache and change
 *  the type to <code>CACHE_TYPE_LRU</code>.
 *
 *@param  domainClass  class instance of the domain.
 *@param  size         size of the cache.
 *///from w  w w  .jav  a2s .  c  o m
public static void setMaxCacheSize(Class domainClass, int size) {
    if (size <= 0) {
        return;
    }
    ClassCache cache = findOrCreateCache(domainClass);
    synchronized (cache) {
        if (cache.type == CACHE_TYPE_ALL) {
            cache.clear();
        }
        cache.maxSize = size;
        if (cache.type == CACHE_TYPE_LRU) {
            LRUMap m = (LRUMap) cache.map;
            m.setMaximumSize(size);
        } else {
            cache.map = new LRUMap(size);
            cache.type = CACHE_TYPE_LRU;
        }
    }
}