com.evanmclean.evlib.cache
Interface ConcurrentHashMapCache<K,V>

Type Parameters:
K -
V -
All Superinterfaces:
ConcurrentMap<K,V>, Map<K,V>

public interface ConcurrentHashMapCache<K,V>
extends ConcurrentMap<K,V>

A thread-safe hash map where the entries expire after a specified time-to-live. The cache is designed such that read-only operations such as Map.get(Object) are fast while operations that modify the map may be wrapped in ReentrantLocks where necessary.

Author:
Evan McLean McLean Computer Services (see the overview for copyright and licensing.)

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 boolean containsKey(Object key)
          Tests if the specified object is a key in this table.
 boolean containsValue(Object value)
          Returns true if this map maps one or more keys to the specified value.
 CacheManager getCacheManager()
          Get the cache manager responsible for this cache.
 int getMaxEntries()
          The maximum number of entries this map will contain.
 String getName()
          Get the name of this cache.
 long getTtlMillis()
          The default number of milliseconds each entry in the map will stay before being cleared out.
 boolean isRefreshTtl()
          If true, entries retrieved with Map.get(Object) or similar will have their expiry time refreshed.
 V put(K key, V value, long thisttl_millisec)
          Put an entry in with the specific time to live.
 V put(K key, V value, long thisttl, TimeUnit time_unit)
          Put an entry in with the specific time to live.
 void putAll(Map<? extends K,? extends V> map, long thisttl_millisec)
          Copies all of the mappings from the specified map to this map, with a specific time to live.
 void putAll(Map<? extends K,? extends V> map, long thisttl, TimeUnit time_unit)
          Copies all of the mappings from the specified map to this map, with the specified time to live.
 V putIfAbsent(K key, V value, long thisttl_millisec)
          If the specified key is not already associated with a value, associate it with the given value using a specified time to live.
 V putIfAbsent(K key, V value, long thisttl, TimeUnit time_unit)
          If the specified key is not already associated with a value, associate it with the given value using a specified time to live.
 V replace(K key, V value, long thisttl_millisec)
          Replaces the entry for a key only if currently mapped to some value.
 V replace(K key, V value, long thisttl, TimeUnit time_unit)
          Replaces the entry for a key only if currently mapped to some value.
 boolean replace(K key, V old_value, V new_value, long thisttl_millisec)
          Replaces the entry for a key only if currently mapped to a given value.
 boolean replace(K key, V old_value, V new_value, long thisttl, TimeUnit time_unit)
          Replaces the entry for a key only if currently mapped to a given value.
 void setMaxEntries(int max_entries)
          Set the maximum number of entries the map can contain (zero for unbounded).
 void setTtl(long ttl, TimeUnit time_unit)
          Set the default time to live for new entries.
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, remove, replace, replace
 
Methods inherited from interface java.util.Map
clear, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Method Detail

containsKey

boolean containsKey(Object key)
Tests if the specified object is a key in this table.

Specified by:
containsKey in interface Map<K,V>
Parameters:
key - Possible key.
Returns:
true if and only if the specified object is a key in this table, as determined by the equals method; false otherwise.

containsValue

boolean containsValue(Object value)
Returns true if this map maps one or more keys to the specified value. Note: This method requires a full internal traversal of the hash table, and so is much slower than method containsKey.

Specified by:
containsValue in interface Map<K,V>
Parameters:
value - Value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.

getCacheManager

CacheManager getCacheManager()
Get the cache manager responsible for this cache.

Returns:
Get the cache manager responsible for this cache.

getMaxEntries

int getMaxEntries()
The maximum number of entries this map will contain.

Returns:
The maximum number of entries this map will contain. 0 for unbounded.

getName

String getName()
Get the name of this cache.

Returns:
Get the name of this cache.

getTtlMillis

long getTtlMillis()
The default number of milliseconds each entry in the map will stay before being cleared out.

Returns:
The default number of milliseconds each entry in the map will stay before being cleared out.

isRefreshTtl

boolean isRefreshTtl()
If true, entries retrieved with Map.get(Object) or similar will have their expiry time refreshed.

Returns:
True if entries get their expiry time refreshed on a get.

put

V put(K key,
      V value,
      long thisttl_millisec)
Put an entry in with the specific time to live.

Parameters:
key -
value -
thisttl_millisec -
Returns:
The original entry (if any).

put

V put(K key,
      V value,
      long thisttl,
      TimeUnit time_unit)
Put an entry in with the specific time to live.

Parameters:
key -
value -
thisttl -
time_unit -
Returns:
The original entry (if any).

putAll

void putAll(Map<? extends K,? extends V> map,
            long thisttl_millisec)
Copies all of the mappings from the specified map to this map, with a specific time to live.

Parameters:
map -
thisttl_millisec -

putAll

void putAll(Map<? extends K,? extends V> map,
            long thisttl,
            TimeUnit time_unit)
Copies all of the mappings from the specified map to this map, with the specified time to live.

Parameters:
map -
thisttl -
time_unit -

putIfAbsent

V putIfAbsent(K key,
              V value,
              long thisttl_millisec)
If the specified key is not already associated with a value, associate it with the given value using a specified time to live.

Parameters:
key -
value -
thisttl_millisec -
Returns:
The previous value associated with the specified key, or null if there was no mapping for the key.

putIfAbsent

V putIfAbsent(K key,
              V value,
              long thisttl,
              TimeUnit time_unit)
If the specified key is not already associated with a value, associate it with the given value using a specified time to live.

Parameters:
key -
value -
thisttl -
time_unit -
Returns:
The previous value associated with the specified key, or null if there was no mapping for the key.

replace

V replace(K key,
          V value,
          long thisttl_millisec)
Replaces the entry for a key only if currently mapped to some value. The replaced value with have a specified time to live.

Parameters:
key -
value -
thisttl_millisec -
Returns:
The previous value associated with the specified key, or null if there was no mapping for the key.

replace

V replace(K key,
          V value,
          long thisttl,
          TimeUnit time_unit)
Replaces the entry for a key only if currently mapped to some value. The replaced value with have a specified time to live.

Parameters:
key -
value -
thisttl -
time_unit -
Returns:
The previous value associated with the specified key, or null if there was no mapping for the key.

replace

boolean replace(K key,
                V old_value,
                V new_value,
                long thisttl_millisec)
Replaces the entry for a key only if currently mapped to a given value. The replaced value with have a specified time to live.

Parameters:
key -
old_value -
new_value -
thisttl_millisec -
Returns:
True if the value was replaced.

replace

boolean replace(K key,
                V old_value,
                V new_value,
                long thisttl,
                TimeUnit time_unit)
Replaces the entry for a key only if currently mapped to a given value. The replaced value with have a specified time to live.

Parameters:
key -
old_value -
new_value -
thisttl -
time_unit -
Returns:
True if the value was replaced.

setMaxEntries

void setMaxEntries(int max_entries)
Set the maximum number of entries the map can contain (zero for unbounded).

Parameters:
max_entries -

setTtl

void setTtl(long ttl,
            TimeUnit time_unit)
Set the default time to live for new entries.

Parameters:
ttl -
time_unit -