org.ehcache.core
Class Ehcache<K,V>

java.lang.Object
  extended by org.ehcache.core.Ehcache<K,V>
All Implemented Interfaces:
java.lang.Iterable<Cache.Entry<K,V>>, Cache<K,V>, UserManagedCache<K,V>

public class Ehcache<K,V>
extends java.lang.Object
implements Cache<K,V>, UserManagedCache<K,V>


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.ehcache.Cache
Cache.Entry<K,V>
 
Field Summary
protected  org.slf4j.Logger logger
           
 
Constructor Summary
Ehcache(CacheConfiguration<K,V> configuration, Store<K,V> store, CacheEventDispatcher<K,V> eventDispatcher, org.slf4j.Logger logger)
           
Ehcache(CacheConfiguration<K,V> configuration, Store<K,V> store, CacheLoaderWriter<? super K,V> cacheLoaderWriter, CacheEventDispatcher<K,V> eventDispatcher, org.slf4j.Logger logger)
           
 
Method Summary
 void addHook(LifeCycled hook)
           
 void clear()
          Removes all mapping currently present in the Cache without invoking the CacheLoaderWriter or any registered CacheEventListener instances This is not an atomic operation and can potentially be very expensive
 void close()
          Releases all data held in this UserManagedCache.
 boolean containsKey(K key)
          Checks whether a mapping for the given key is present, without retrieving the associated value
 V get(K key)
          Retrieve the value currently mapped to the provided key
 java.util.Map<K,V> getAll(java.util.Set<? extends K> keys)
          Retrieves all values associated with the given keys.
 java.util.Map<BulkOps,org.terracotta.statistics.jsr166e.LongAdder> getBulkMethodEntries()
           
 CacheLoaderWriter<? super K,V> getCacheLoaderWriter()
           
 Jsr107Cache<K,V> getJsr107Cache()
           
 CacheRuntimeConfiguration<K,V> getRuntimeConfiguration()
          Exposes the CacheRuntimeConfiguration associated with this Cache instance.
 Status getStatus()
          Returns the current Status for this CacheManager
 void init()
          Attempts at having this UserManagedCache go to Status.AVAILABLE.
 java.util.Iterator<Cache.Entry<K,V>> iterator()
           
 void put(K key, V value)
          Associates the provided value to the given key
 void putAll(java.util.Map<? extends K,? extends V> entries)
          Associates all the provided key:value pairs.
 V putIfAbsent(K key, V value)
          If the provided key is not associated with a value, then associate it with the provided value.
 void remove(K key)
          Removes the value, if any, associated with the provided key
 boolean remove(K key, V value)
          If the provided key is associated with the provided value then remove the entry.
 void removeAll(java.util.Set<? extends K> keys)
          Removes any associates for the given keys.
 V replace(K key, V value)
          If the provided key is associated with a value, then replace that value with the provided value.
 boolean replace(K key, V oldValue, V newValue)
          If the provided key is associated with oldValue, then replace that value with newValue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.slf4j.Logger logger
Constructor Detail

Ehcache

public Ehcache(CacheConfiguration<K,V> configuration,
               Store<K,V> store,
               CacheEventDispatcher<K,V> eventDispatcher,
               org.slf4j.Logger logger)

Ehcache

public Ehcache(CacheConfiguration<K,V> configuration,
               Store<K,V> store,
               CacheLoaderWriter<? super K,V> cacheLoaderWriter,
               CacheEventDispatcher<K,V> eventDispatcher,
               org.slf4j.Logger logger)
Method Detail

getBulkMethodEntries

public java.util.Map<BulkOps,org.terracotta.statistics.jsr166e.LongAdder> getBulkMethodEntries()

get

public V get(K key)
      throws CacheLoadingException
Description copied from interface: Cache
Retrieve the value currently mapped to the provided key

Specified by:
get in interface Cache<K,V>
Parameters:
key - the key to query the value for
Returns:
the value mapped to the key, null if none
Throws:
CacheLoadingException - if the CacheLoaderWriter associated with this cache was invoked and threw an Exception

put

public void put(K key,
                V value)
         throws CacheWritingException
Description copied from interface: Cache
Associates the provided value to the given key

Specified by:
put in interface Cache<K,V>
Parameters:
key - the key, may not be null
value - the value, may not be null
Throws:
CacheWritingException - if the CacheLoaderWriter associated with this cache threw an Exception while writing the value for the given key to underlying system of record.

containsKey

public boolean containsKey(K key)
Description copied from interface: Cache
Checks whether a mapping for the given key is present, without retrieving the associated value

Specified by:
containsKey in interface Cache<K,V>
Parameters:
key - the key
Returns:
true if a mapping is present, false otherwise

remove

public void remove(K key)
            throws CacheWritingException
Description copied from interface: Cache
Removes the value, if any, associated with the provided key

Specified by:
remove in interface Cache<K,V>
Parameters:
key - the key to remove the value for
Throws:
CacheWritingException - if the CacheLoaderWriter associated with this cache threw an Exception while removing the value for the given key from the underlying system of record.

clear

public void clear()
Description copied from interface: Cache
Removes all mapping currently present in the Cache without invoking the CacheLoaderWriter or any registered CacheEventListener instances This is not an atomic operation and can potentially be very expensive

Specified by:
clear in interface Cache<K,V>

iterator

public java.util.Iterator<Cache.Entry<K,V>> iterator()
Specified by:
iterator in interface java.lang.Iterable<Cache.Entry<K,V>>

getAll

public java.util.Map<K,V> getAll(java.util.Set<? extends K> keys)
                          throws BulkCacheLoadingException
Description copied from interface: Cache
Retrieves all values associated with the given keys.

Specified by:
getAll in interface Cache<K,V>
Parameters:
keys - keys to query for
Returns:
a map from keys to values or null if the key was not mapped
Throws:
BulkCacheLoadingException - if loading some or all values failed

putAll

public void putAll(java.util.Map<? extends K,? extends V> entries)
            throws BulkCacheWritingException
Description copied from interface: Cache
Associates all the provided key:value pairs.

Specified by:
putAll in interface Cache<K,V>
Parameters:
entries - key:value pairs to associate
Throws:
BulkCacheWritingException - if the CacheLoaderWriter associated with this cache threw an Exception while writing given key:value pairs to underlying system of record.

removeAll

public void removeAll(java.util.Set<? extends K> keys)
               throws BulkCacheWritingException
Description copied from interface: Cache
Removes any associates for the given keys.

Specified by:
removeAll in interface Cache<K,V>
Parameters:
keys - keys to remove values for
Throws:
BulkCacheWritingException - if the CacheLoaderWriter associated with this cache threw an Exception while removing mappings for given keys from underlying system of record.

putIfAbsent

public V putIfAbsent(K key,
                     V value)
              throws CacheWritingException
Description copied from interface: Cache
If the provided key is not associated with a value, then associate it with the provided value.

Specified by:
putIfAbsent in interface Cache<K,V>
Parameters:
key - the key to be associated with
value - the value to associate
Returns:
the value that was associated with the key, or null if none
Throws:
CacheWritingException - if the CacheLoaderWriter associated with this cache threw an Exception while writing the value for the given key to underlying system of record.

remove

public boolean remove(K key,
                      V value)
               throws CacheWritingException
Description copied from interface: Cache
If the provided key is associated with the provided value then remove the entry.

Specified by:
remove in interface Cache<K,V>
Parameters:
key - the key to remove
value - the value to check against
Returns:
true if the entry was removed
Throws:
CacheWritingException - if the CacheLoaderWriter associated with this cache threw an Exception while removing the given key:value mapping

replace

public V replace(K key,
                 V value)
          throws CacheLoadingException,
                 CacheWritingException
Description copied from interface: Cache
If the provided key is associated with a value, then replace that value with the provided value.

Specified by:
replace in interface Cache<K,V>
Parameters:
key - the key to be associated with
value - the value to associate
Returns:
the value that was associated with the key, or null if none
Throws:
CacheLoadingException - if the CacheLoaderWriter associated with this cache was invoked and threw an Exception while loading the value for the key
CacheWritingException - if the CacheLoaderWriter associated with this cache was invoked and threw an Exception while replacing value for given key on underlying system of record.

replace

public boolean replace(K key,
                       V oldValue,
                       V newValue)
                throws CacheLoadingException,
                       CacheWritingException
Description copied from interface: Cache
If the provided key is associated with oldValue, then replace that value with newValue.

Specified by:
replace in interface Cache<K,V>
Parameters:
key - the key to be associated with
oldValue - the value to check against
newValue - the value to associate
Returns:
true if the value was replaced
Throws:
CacheLoadingException - if the CacheLoaderWriter associated with this cache was invoked and threw an Exception while loading the value for the key
CacheWritingException - if the CacheLoaderWriter associated with this cache was invoked and threw an Exception while replacing value for given key on underlying system of record.

getRuntimeConfiguration

public CacheRuntimeConfiguration<K,V> getRuntimeConfiguration()
Description copied from interface: Cache
Exposes the CacheRuntimeConfiguration associated with this Cache instance.

Specified by:
getRuntimeConfiguration in interface Cache<K,V>
Returns:
the configuration currently in use

init

public void init()
Attempts at having this UserManagedCache go to Status.AVAILABLE.

Should this throw, while the UserManagedCache isn't yet Status.AVAILABLE, it will try to go back to Status.UNINITIALIZED properly.

Specified by:
init in interface UserManagedCache<K,V>

close

public void close()
Description copied from interface: UserManagedCache
Releases all data held in this UserManagedCache.

Should this throw, while the UserManagedCache isn't yet Status.UNINITIALIZED, it will keep on trying to go to Status.UNINITIALIZED properly.

Specified by:
close in interface UserManagedCache<K,V>

getStatus

public Status getStatus()
Description copied from interface: UserManagedCache
Returns the current Status for this CacheManager

Specified by:
getStatus in interface UserManagedCache<K,V>
Returns:
the current Status

addHook

public void addHook(LifeCycled hook)

getJsr107Cache

public Jsr107Cache<K,V> getJsr107Cache()

getCacheLoaderWriter

public CacheLoaderWriter<? super K,V> getCacheLoaderWriter()