org.terracotta.cache
Interface DistributedCache<K,V>

Type Parameters:
K - Key type
V - Value type
All Superinterfaces:
ConcurrentMap<K,V>, LockableMap<K>, Map<K,V>
All Known Implementing Classes:
ClusteredStoreBackend, DistributedCacheImpl, LocalCache

public interface DistributedCache<K,V>
extends ConcurrentMap<K,V>, LockableMap<K>

DistributedCache is a distributed, Terracotta-backed, clustered cache with eviction. Object identity is maintained across the cluster such that an object put into the cache is seen as the same object across all nodes and changes to that object will be maintained across all nodes. Note that this implies that changes to keys or values held in the DistributedCache must be done with appropriate locking on the key or value object to maintain proper Java memory model semantics.


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 CacheConfig getConfig()
          Get the current config for the cache (which may or may not be the config passed to the cache originally.
 String getLockIdForKey(K key)
          Retrieves a lock ID that's specific for this cache and key.
 TimestampedValue<V> getTimestampedValue(K key)
          Get the value wrapped in a timestamped object.
 TimestampedValue<V> getTimestampedValueQuiet(K key)
          Get the value wrapped in a timestamped object without updating the last usage statistics.
 int localSize()
          Get the number of elements local in the current node - this number should always be less than size(), and is likely to be different.
 void putNoReturn(K key, V value)
          Put the key/value into the map, replacing the existing value if present.
 void removeNoReturn(Object key)
          Remove the key from the map, if it exists.
 TimestampedValue<V> removeTimestampedValue(K key)
          Remove the timestamped value for the given key.
 void shutdown()
          Shut down the background eviction thread, if any.
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, remove, replace, replace
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from interface org.terracotta.collections.LockableMap
createFinegrainedLock, lockEntry, unlockEntry
 

Method Detail

putNoReturn

void putNoReturn(K key,
                 V value)
Put the key/value into the map, replacing the existing value if present. This method differs from the normal put() method only in that it returns void instead of the prior value. This is important in the cluster as it avoids faulting that value to return when it is rarely used.

Parameters:
key - Key
value - Value

removeNoReturn

void removeNoReturn(Object key)
Remove the key from the map, if it exists. This method differs from the normal remove() method only in that it returns void instead of the prior value. This is important in the cluster as it avoids faulting that value to return when it is rarely used.

Parameters:
key - Key

getTimestampedValue

TimestampedValue<V> getTimestampedValue(K key)
Get the value wrapped in a timestamped object. This value is used entirely for maintaining the creation and last accessed time for TTI and TTL eviction.

Parameters:
key - The key to search for
Returns:
The wrapped value or null if not found

getTimestampedValueQuiet

TimestampedValue<V> getTimestampedValueQuiet(K key)
Get the value wrapped in a timestamped object without updating the last usage statistics.

Parameters:
key - The key to search for
Returns:
The wrapped value or null if not found
See Also:
getTimestampedValue(Object)

removeTimestampedValue

TimestampedValue<V> removeTimestampedValue(K key)
Remove the timestamped value for the given key. Previous values will be returned as null if they're expired.

Parameters:
key - The key to search for
Returns:
The wrapped value or null if not found or expired

getConfig

CacheConfig getConfig()
Get the current config for the cache (which may or may not be the config passed to the cache originally.

Returns:
The configuration for this cache

localSize

int localSize()
Get the number of elements local in the current node - this number should always be less than size(), and is likely to be different.

Returns:
The local size, in range, such that 0 < localSize < size

shutdown

void shutdown()
Shut down the background eviction thread, if any.


getLockIdForKey

String getLockIdForKey(K key)
Retrieves a lock ID that's specific for this cache and key.



Copyright © 2010 Terracotta, Inc.. All Rights Reserved.