org.terracotta.toolkit.cache
Interface ToolkitCache<K,V>

All Superinterfaces:
ConcurrentMap<K,V>, Destroyable, Map<K,V>, SearchableMap<K,V>, ToolkitBulkLoadObject, ToolkitObject

public interface ToolkitCache<K,V>
extends ConcurrentMap<K,V>, Destroyable, SearchableMap<K,V>, ToolkitBulkLoadObject

A toolkit cache. A toolkit cache can be configured using various configs available in ToolkitConfigFields. Consult Toolkit.getCache(String, Configuration, Class) for more info on various configs.

Consult the class level docs for more info on behavior regarding destroy.

Trying to add values that are not serializable will throw NotSerializableRuntimeException


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 void addListener(ToolkitCacheListener<K> listener)
          Adds a listener to this cache - the listener will not be added again if it's already registered.
 ToolkitReadWriteLock createLockForKey(K key)
          Creates a ToolkitReadWriteLock for the given key.
 Map<K,V> getAll(Collection<? extends K> keys)
          Perform get for the given set of keys.
 Map<K,V> getAllQuiet(Collection<K> keys)
          Similar to getAll(Collection), but doesn't update lastAccessedTime
 Configuration getConfiguration()
          Returns the configuration of this cache.
 V getQuiet(Object key)
          Same as Map.get(Object) but does not update the lastAccessedTime
 V putIfAbsent(K key, V value, long createTimeInSecs, int maxTTISeconds, int maxTTLSeconds)
          Similar to ConcurrentMap.putIfAbsent(Object, Object) but with ability to specify creation time, tti, ttl etc.
 void putNoReturn(K key, V value)
          Behaves the same as the standard Map.put(Object, Object) method except that the previous value is not returned.
 void putNoReturn(K key, V value, long createTimeInSecs, int maxTTISeconds, int maxTTLSeconds)
          Similar to putNoReturn(Object, Object) but with ability to specify creation time, tti, ttl etc
 void removeListener(ToolkitCacheListener<K> listener)
          Removes a registered listener from this cache.
 void removeNoReturn(Object key)
          Behaves the same as the standard Map.remove(Object) method except that the previous value is not returned.
 void setConfigField(String name, Serializable value)
          Updates the configuration of the Cache using passed in value.
 
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.toolkit.object.Destroyable
destroy, isDestroyed
 
Methods inherited from interface org.terracotta.toolkit.search.SearchableMap
createQueryBuilder, setAttributeExtractor
 
Methods inherited from interface org.terracotta.toolkit.bulkload.ToolkitBulkLoadObject
isBulkLoadEnabled, isNodeBulkLoadEnabled, setNodeBulkLoadEnabled, waitUntilBulkLoadComplete
 
Methods inherited from interface org.terracotta.toolkit.object.ToolkitObject
getName
 

Method Detail

removeNoReturn

void removeNoReturn(Object key)
Behaves the same as the standard Map.remove(Object) method except that the previous value is not returned. This may provide significant performance improvements when the old value is not required.

Parameters:
key - the key of the entry to remove

putNoReturn

void putNoReturn(K key,
                 V value)
Behaves the same as the standard Map.put(Object, Object) method except that the previous value is not returned. This may provide significant performance improvements when old value is not required.

Parameters:
key - the key of the entry
value - the value of the entry

getAll

Map<K,V> getAll(Collection<? extends K> keys)
Perform get for the given set of keys. Keys which are not present in the Cache will have null values associated with them in the returned map. The returned map is unmodifiable.

Parameters:
keys - the collection of keys to lookup
Returns:
a map of keys and the value mapped to the given key (but not necessarily the current mapping)

getConfiguration

Configuration getConfiguration()
Returns the configuration of this cache.

Returns:
the configuration of this cache

setConfigField

void setConfigField(String name,
                    Serializable value)
Updates the configuration of the Cache using passed in value. Throws IllegalArgumentException if the config field name is not dynamic and cannot be changed at runtime


createLockForKey

ToolkitReadWriteLock createLockForKey(K key)
Creates a ToolkitReadWriteLock for the given key.

NOTE: ToolkitObject.getName() on the ToolkitReadWriteLock, ToolkitReadWriteLock.readLock() and ToolkitReadWriteLock.writeLock() will return null

Parameters:
key - the key for which a lock will be returned
Returns:
an instance of ToolkitReadWriteLock that can be used to perform primitive locking operations on the key

getQuiet

V getQuiet(Object key)
Same as Map.get(Object) but does not update the lastAccessedTime

Parameters:
key - the key
Returns:
value mapped to the key or null otherwise

getAllQuiet

Map<K,V> getAllQuiet(Collection<K> keys)
Similar to getAll(Collection), but doesn't update lastAccessedTime

Parameters:
keys - the collection of keys to lookup
Returns:
a map of keys and the value mapped to the given key (but not necessarily the current mapping)

putNoReturn

void putNoReturn(K key,
                 V value,
                 long createTimeInSecs,
                 int maxTTISeconds,
                 int maxTTLSeconds)
Similar to putNoReturn(Object, Object) but with ability to specify creation time, tti, ttl etc

Parameters:
key - the key
value - the value
createTimeInSecs - creation time in seconds since epoch
maxTTISeconds - tti of the entry
maxTTLSeconds - ttl of the entry

putIfAbsent

V putIfAbsent(K key,
              V value,
              long createTimeInSecs,
              int maxTTISeconds,
              int maxTTLSeconds)
Similar to ConcurrentMap.putIfAbsent(Object, Object) but with ability to specify creation time, tti, ttl etc.

Parameters:
key - the key
value - the value
createTimeInSecs - creation time in seconds since epoch
maxTTISeconds - tti of the entry
maxTTLSeconds - ttl of the entry
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key.

addListener

void addListener(ToolkitCacheListener<K> listener)
Adds a listener to this cache - the listener will not be added again if it's already registered. Listeners are notified in the order they are added.


removeListener

void removeListener(ToolkitCacheListener<K> listener)
Removes a registered listener from this cache. Does nothing if the listener is not registered already



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