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

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

Introduction

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

Prototype

public LRUMap(final Map<? extends K, ? extends V> map) 

Source Link

Document

Constructor copying elements from another map.

Usage

From source file:Model.CacheInMemory.java

public CacheInMemory(int maxItems) {
    cacheMap = new LRUMap(maxItems);
}

From source file:Model.CacheInMemory.java

public CacheInMemory(long timeToLive, final long timerInterval, int maxItems) {
    this.timeToLive = timeToLive * 1000;

    cacheMap = new LRUMap(maxItems);

    if (timeToLive > 0 && timerInterval > 0) {

        Thread t = new Thread(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(timerInterval * 1000);
                    } catch (InterruptedException ex) {
                    }/*from  w ww.  ja  v a 2  s .  co  m*/
                    cleanup();
                }
            }
        });

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

From source file:net.ontopia.persistence.proxy.TransactionalLRULookupIndex.java

public TransactionalLRULookupIndex(CacheIF cache, int lrusize) {
    this.cache = cache;
    this.lru = Collections.synchronizedMap(new LRUMap(lrusize));
    this.lrusize = lrusize;
}

From source file:imitationLearning.WordSequenceCache.java

/**
 *
 * @param timeToLive/*from   ww w .j av a  2 s .  c o m*/
 * @param timerInterval
 * @param maxItems
 */
public WordSequenceCache(long timeToLive, final long timerInterval, int maxItems) {
    this.timeToLive = timeToLive * 1_000;

    cacheMap = new LRUMap(maxItems);

    if (timeToLive > 0 && timerInterval > 0) {

        Thread t = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(timerInterval * 1_000);
                } catch (InterruptedException ex) {
                }
                cleanup();
            }
        });

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

From source file:net.ontopia.persistence.proxy.QueryCache.java

QueryCache(DetachedQueryIF query, CacheIF cache, int lrusize) {
    this.query = query;
    this.cache = cache;
    this.lru = Collections.synchronizedMap(new LRUMap(lrusize));
    this.lrusize = lrusize;
}

From source file:net.ontopia.topicmaps.impl.rdbms.QueryLookup.java

public QueryLookup(String qname, TransactionIF txn, int lrusize) {
    this.qname = qname;
    this.txn = txn;
    this.cache = new ReferenceMap(AbstractReferenceMap.ReferenceStrength.SOFT,
            AbstractReferenceMap.ReferenceStrength.HARD);
    this.lru = new LRUMap(lrusize);
}

From source file:net.ontopia.persistence.proxy.ROTransaction.java

public ROTransaction(StorageAccessIF access) {
    super("TX" + access.getId(), access);

    // initialize shared data cache
    StorageCacheIF scache = access.getStorage().getStorageCache();
    this.txncache = new ROLocalCache(this, scache);

    // initialize identity map
    this.lrusize = PropertyUtils
            .getInt(access.getProperty("net.ontopia.topicmaps.impl.rdbms.Cache.shared.identitymap.lru"), 5000);
    this.lru = new LRUMap(this.lrusize);

    // instrument transaction cache
    int dinterval = PropertyUtils
            .getInt(access.getStorage().getProperty("net.ontopia.topicmaps.impl.rdbms.Cache.local.debug"), -1);
    if (dinterval > 0) {
        log.info("Instrumenting local cache.");
        this.txncache = new StatisticsCache("lcache", this.txncache, dinterval);
    }/*w  w  w . jav  a2  s . co  m*/

    // Get access registrar from transaction cache (currently the
    // local data cache)
    this.registrar = txncache.getRegistrar();

    // Use IdentityIF object access
    this.oaccess = new PersistentObjectAccess(this);
}

From source file:com.pungwe.db.io.store.InstanceCachingStore.java

public InstanceCachingStore(Store store, int cacheSize) {
    this.store = store;
    this.cacheSize = cacheSize;
    cache = new LRUMap<>(cacheSize);
}

From source file:com.musenkishi.wally.util.PaletteLoader.java

public static PaletteBuilder with(Context context, String id) {
    if (colorSchemeCache == null) {
        colorSchemeCache = Collections.synchronizedMap(new LRUMap<String, Palette>(MAX_ITEMS_IN_CACHE));
    }/*from  w  w  w.ja v a  2 s.  co m*/
    if (uiHandler == null || backgroundHandler == null) {
        setupHandlers(context);
    }
    return new PaletteBuilder(id);
}

From source file:ch.cyberduck.core.Cache.java

public Cache(int size) {
    if (size == Integer.MAX_VALUE) {
        // Unlimited
        impl = Collections.synchronizedMap(new LinkedHashMap<T, AttributedList<T>>());
        reverse = Collections.synchronizedMap(new LinkedHashMap<CacheReference, T>());
    } else if (size == 0) {
        impl = Collections.emptyMap();
        reverse = Collections.emptyMap();
    } else {/*ww  w .java2  s . com*/
        // Will inflate to the given size
        impl = Collections.synchronizedMap(new LRUMap<T, AttributedList<T>>(size));
        reverse = Collections.synchronizedMap(new LinkedHashMap<CacheReference, T>());
    }
}