org.infinispan.container
Class LRUDataContainer

java.lang.Object
  extended by org.infinispan.container.FIFODataContainer
      extended by org.infinispan.container.LRUDataContainer
All Implemented Interfaces:
Iterable<InternalCacheEntry>, DataContainer

@ThreadSafe
public class LRUDataContainer
extends FIFODataContainer

Based on the same techniques outlined in the FIFODataContainer, this implementation additionally unlinks and re-links entries at the tail whenever entries are visited (using a get()) or are updated (a put() on an existing key).

Again, these are constant-time operations.

Note though that this implementation does have a far lesser degree of concurrency when compared with its FIFO variant due to the segment locking necessary even when doing a get() (since gets reorder links). This has a knock-on effect not just on get() but even on other write() operations since they all compete for the same segment lock (when working on keys mapped to the same segment, of course).

Since:
4.0
Author:
Manik Surtani

Nested Class Summary
 
Nested classes/interfaces inherited from class org.infinispan.container.FIFODataContainer
FIFODataContainer.EntryIterator, FIFODataContainer.EntrySet, FIFODataContainer.ImmutableEntryIterator, FIFODataContainer.KeyIterator, FIFODataContainer.KeySet, FIFODataContainer.LinkedIterator, FIFODataContainer.ValueIterator, FIFODataContainer.Values
 
Constructor Summary
LRUDataContainer(int concurrencyLevel)
           
 
Method Summary
 InternalCacheEntry get(Object k)
          Retrieves a cached entry
 void put(Object k, Object v, long lifespan, long maxIdle)
          Puts an entry in the cache along with a lifespan and a maxIdle time
protected  void updateLinks(org.infinispan.container.FIFODataContainer.LinkedEntry le)
           
 
Methods inherited from class org.infinispan.container.FIFODataContainer
clear, containsKey, correctPrev, entrySet, getNext, initLinks, isMarkedForRemoval, iterator, keySet, linkAtEnd, markNextReference, markPrevReference, peek, purgeExpired, remove, size, unlink, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LRUDataContainer

public LRUDataContainer(int concurrencyLevel)
Method Detail

get

public InternalCacheEntry get(Object k)
Description copied from interface: DataContainer
Retrieves a cached entry

Specified by:
get in interface DataContainer
Overrides:
get in class FIFODataContainer
Parameters:
k - key under which entry is stored
Returns:
entry, if it exists and has not expired, or null if not

put

public void put(Object k,
                Object v,
                long lifespan,
                long maxIdle)
Description copied from interface: DataContainer
Puts an entry in the cache along with a lifespan and a maxIdle time

Specified by:
put in interface DataContainer
Overrides:
put in class FIFODataContainer
Parameters:
k - key under which to store entry
v - value to store
lifespan - lifespan in milliseconds. -1 means immortal.
maxIdle - max idle time for which to store entry. -1 means forever.

updateLinks

protected final void updateLinks(org.infinispan.container.FIFODataContainer.LinkedEntry le)

Google Analytics

Copyright © 2010 JBoss, a division of Red Hat. All Rights Reserved.