com.twitter.common.util.caching
Class LRUCache<K,V>

java.lang.Object
  extended by com.twitter.common.util.caching.LRUCache<K,V>
All Implemented Interfaces:
Cache<K,V>

public class LRUCache<K,V>
extends Object
implements Cache<K,V>

A cache with a fixed maximum size, evicting items that were used least-recently. WARNING: This is not thread-safe. If you wish to get a thread-safe version of a constructed LRUCache, you must wrap it with Collections.synchronizedMap(java.util.Map).


Nested Class Summary
static class LRUCache.Builder<K,V>
           
 
Method Summary
static
<K,V> LRUCache.Builder<K,V>
builder()
           
 Collection<V> copyValues()
           
 void delete(K key)
          Deletes an entry from the cache.
 V get(K key)
          Fetches a value from the cache.
 long getAccesses()
           
 double getHitRate()
           
 long getMisses()
           
 void put(K key, V value)
          Stores a key-value pair in the cache.
 int size()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

builder

public static <K,V> LRUCache.Builder<K,V> builder()

get

public V get(K key)
Description copied from interface: Cache
Fetches a value from the cache.

Specified by:
get in interface Cache<K,V>
Parameters:
key - The key for the value to fetch, must not be null.
Returns:
The cached value corresponding with key, or null if no entry exists.

put

public void put(K key,
                V value)
Description copied from interface: Cache
Stores a key-value pair in the cache.

Specified by:
put in interface Cache<K,V>
Parameters:
key - The key to store, must not be null.
value - The value to store, must not be null.

delete

public void delete(K key)
Description copied from interface: Cache
Deletes an entry from the cache.

Specified by:
delete in interface Cache<K,V>
Parameters:
key - Key for the value to delete, must not be null.

size

public int size()

toString

public String toString()
Overrides:
toString in class Object

copyValues

public Collection<V> copyValues()

getAccesses

public long getAccesses()

getMisses

public long getMisses()

getHitRate

public double getHitRate()