com.netflix.servo.util
Class ExpiringCache<K,V>

java.lang.Object
  extended by com.netflix.servo.util.ExpiringCache<K,V>
Type Parameters:
K - The type of keys maintained
V - The type of values maintained

public class ExpiringCache<K,V>
extends java.lang.Object

A semi-persistent mapping from keys to values. Values are automatically loaded by the cache, and are stored in the cache until evicted.


Constructor Summary
ExpiringCache(long expireAfterMs, ConcurrentHashMapV8.Fun<K,V> getter)
          Create a new ExpiringCache that will expire entries after a given number of milliseconds computing the values as needed using the given getter.
ExpiringCache(long expireAfterMs, ConcurrentHashMapV8.Fun<K,V> getter, long expirationFreqMs)
          For unit tests.
 
Method Summary
 V get(K key)
          Get the (possibly cached) value for a given key.
 int size()
          Return the number of entries in the cache.
 java.lang.String toString()
          
 java.util.List<V> values()
          Get the list of all values that are members of this cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExpiringCache

public ExpiringCache(long expireAfterMs,
                     ConcurrentHashMapV8.Fun<K,V> getter)
Create a new ExpiringCache that will expire entries after a given number of milliseconds computing the values as needed using the given getter.

Parameters:
expireAfterMs - Number of milliseconds after which entries will be evicted
getter - Function that will be used to compute the values

ExpiringCache

public ExpiringCache(long expireAfterMs,
                     ConcurrentHashMapV8.Fun<K,V> getter,
                     long expirationFreqMs)
For unit tests. Create a new ExpiringCache that will expire entries after a given number of milliseconds computing the values as needed using the given getter.

Parameters:
expireAfterMs - Number of milliseconds after which entries will be evicted
getter - Function that will be used to compute the values
expirationFreqMs - Frequency at which to schedule the job that evicts entries from the cache.
Method Detail

get

public V get(K key)
Get the (possibly cached) value for a given key.


values

public java.util.List<V> values()
Get the list of all values that are members of this cache. Does not affect the access time used for eviction.


size

public int size()
Return the number of entries in the cache.


toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object