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

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

Introduction

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

Prototype

public LRUMap(Map map) 

Source Link

Document

Constructor copying elements from another map.

Usage

From source file:ch.cyberduck.AttributeCache.java

public AttributeCache(int size) {
    impl = new LRUMap(size) {
        @Override/*w  w  w.  j a  v a 2s. c o m*/
        protected boolean removeLRU(LinkEntry entry) {
            log.debug("Removing from cache:" + entry);
            return true;
        }
    };
}

From source file:com.discursive.jccook.collections.lazy.LazyMapExample.java

public void start() throws Exception {

    StockQuoteTransformer sqTransformer = new StockQuoteTransformer();
    sqTransformer.setQuoteURL(new URL("http://quotes.company.com"));
    sqTransformer.setTimeout(500);//from w ww . ja  v a  2 s.c om

    stockQuotes = new LRUMap(5);
    stockQuotes = LazyMap.decorate(stockQuotes, sqTransformer);

    // Now use some of the entries in the cache
    Float cscoPrice = (Float) stockQuotes.get("CSCO");
    Float msPrice = (Float) stockQuotes.get("MSFT");
    Float tscPrice = (Float) stockQuotes.get("TSC");
    Float luPrice = (Float) stockQuotes.get("LU");
    Float pPrice = (Float) stockQuotes.get("P");
    Float msPrice2 = (Float) stockQuotes.get("MSFT");

    // Add another price to the Map, this should kick out the LRU item.
    stockQuotes.put("AA", new Float(203.20));

    // CSCO was the first price requested, it is therefor the
    // least recently used.
    if (!stockQuotes.containsKey("CSCO")) {
        System.out.println("As expected CSCO was discarded");
    }
}

From source file:com.epimorphics.registry.util.DescriptionCache.java

public DescriptionCache(int size) {
    cache = new LRUMap(size);
}

From source file:de.hybris.platform.test.LRUMapTest.java

@Test
public void testAgain() {
    final LRUMap map = new LRUMap(2);
    map.put("2", "zwei");
    map.put("3", "drei");

    map.get("2");
    map.put("4", "vier");

    assertEquals("zwei", map.get("2"));
    assertEquals(null, map.get("3"));
    assertEquals("vier", map.get("4"));
}

From source file:com.redhat.persistence.oql.Query.java

public static void setQueryCacheSize(int size) {
    s_cache = new LRUMap(size);
    if (s_log.isDebugEnabled())
        s_log.debug("Reset query cache to size " + size);
}

From source file:net.chat.utils.Cache.java

public Cache(long timeToLiveInSeconds, final long timerIntervalInSeconds, int maxItems) {
    this.timeToLiveInMillis = timeToLiveInSeconds * 1000;

    cacheMap = new LRUMap(maxItems);

    if (timeToLiveInMillis > 0 && timerIntervalInSeconds > 0) {

        Thread t = new Thread(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(timerIntervalInSeconds * 1000);
                    } catch (InterruptedException ex) {
                    }/*  w w  w . ja  va  2  s.  c  om*/

                    cleanup();
                }
            }
        });

        t.setDaemon(true);
        t.start();
    }
}

From source file:com.cyclopsgroup.waterview.core.LRUCacheManager.java

/**
 * Override or implement method of parent class or interface
 *
 * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
 *///ww  w .j a v  a  2 s.com
public void configure(Configuration conf) throws ConfigurationException {
    int size = conf.getChild("size").getValueAsInteger(-1);
    if (size > 1) {
        content = new LRUMap(size);
    }
}

From source file:com.quinsoft.zeidon.utils.TimedLruCache.java

public TimedLruCache(long timeToLiveInSeconds, final long timerIntervalInSeconds, int maxItems) {
    this.timeToLiveInMillis = timeToLiveInSeconds * 1000;

    cacheMap = new LRUMap(maxItems);

    if (timeToLiveInMillis > 0 && timerIntervalInSeconds > 0) {

        Thread t = new Thread(new Runnable() {
            @Override/*  w  w  w. j  a v  a2  s .  c o m*/
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(timerIntervalInSeconds * 1000);
                    } catch (InterruptedException ex) {
                    }

                    cleanup();
                    Thread.yield();
                }
            }
        });

        t.setDaemon(true);
        t.start();
    }
}

From source file:edu.mayo.informatics.cts.utility.ObjectCache.java

private ObjectCache() {
    //A Least Recently Used map will automaticaly discard old items if it is full, 
    //and new items are added.
    values_ = new LRUMap(CTSConstants.CACHE_SIZE.getValue());
}

From source file:ezbake.security.impl.cache.MemoryCache.java

/**
 *
 * @param capacity//  www  . j av a  2s .co m
 * @param expiration in seconds
 */
public MemoryCache(final int capacity, final long expiration) {
    // Enforce greater than zero policy
    int cap = (capacity > 0) ? capacity : DEFAULT_MAX_CAPACITY;
    long exp = (expiration > 0) ? expiration : DEFAULT_CACHE_EXPIRATION;

    lruCache = (Map<Key, CacheValue<Value>>) Collections.synchronizedMap(new LRUMap(cap));
    this.expiration = exp * 1000;

    log.debug("Initialized EzSecurity Cache\ncap:{}\nexp:{}", cap, exp);
}