public class CacheImpl<K,V> extends java.lang.Object implements ObjectCache<K,V>, ByteStreamCache, java.io.Closeable
Cache.Entry<K,V>, Cache.EntryProcessor<K,V>
Constructor and Description |
---|
CacheImpl(CacheManagerImpl localManager,
java.lang.String name,
java.lang.String managerName,
java.lang.String guid,
CacheConfig config) |
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
cacheLoader(java.lang.Object key)
Places an item in the cache from the loader unless the item is in cache already.
|
void |
close() |
boolean |
compareAndRemove(java.lang.Object key,
long version)
Removes the entry from the cache if the current entry matches the version.
|
boolean |
compareVersionAndPut(java.lang.Object key,
long version,
java.lang.Object value)
Updates the cache if the old version matches the current version.
|
boolean |
containsKey(java.lang.Object key)
Returns true if an entry for the item is found in the cache.
|
CacheImpl |
createIfAbsent() |
V |
get(java.lang.Object key)
Returns the object with the given key, checking the backing
store if necessary.
|
boolean |
get(java.lang.Object key,
java.io.OutputStream os)
Fills an output stream with the value for a key.
|
java.util.Map<K,V> |
getAll(java.util.Set<? extends K> keys)
Returns a new map of the items found in the central cache.
|
java.lang.Object |
getAndPut(java.lang.Object key,
java.lang.Object value)
Puts a new item in the cache.
|
java.lang.Object |
getAndRemove(java.lang.Object key) |
java.lang.Object |
getAndReplace(java.lang.Object key,
java.lang.Object value) |
Cache.Entry |
getCacheEntry(java.lang.Object key)
Returns the cache entry for the object with the given key.
|
CacheHandle |
getCacheHandle() |
HashKey |
getCacheKey() |
CacheManager |
getCacheManager() |
CacheConfig |
getConfig() |
Configuration<K,V> |
getConfiguration() |
DataStore |
getDataStore() |
protected DistCacheEntry |
getDistCacheEntry(HashKey key)
Returns the CacheKeyEntry for the given key.
|
protected DistCacheEntry |
getDistCacheEntry(java.lang.Object key)
Returns the CacheKeyEntry for the given key.
|
long |
getExpireTimeout()
The maximum valid time for an item.
|
ExtCacheEntry |
getExtCacheEntry(HashKey key) |
ExtCacheEntry |
getExtCacheEntry(java.lang.Object key)
Returns the cache entry for the object with the given key.
|
java.lang.String |
getGuid() |
long |
getIdleTimeout()
The maximum idle time for an item, which is typically used for
temporary data like sessions.
|
long |
getIdleTimeoutWindow()
Returns the idle check window, used to minimize traffic when
updating access times.
|
HashKey |
getKeyHash(java.lang.Object key)
Returns the hash of the given key
|
byte[] |
getKeyHash(java.lang.String name) |
long |
getLeaseTimeout()
The lease timeout is the time a server can use the local version
if it owns it, before a timeout.
|
ExtCacheEntry |
getLiveCacheEntry(java.lang.Object key)
Returns the entry for the given key, returning the live item.
|
long |
getLocalReadTimeout()
The local read timeout is how long a local copy of
a cache item can be reused before checking with the master copy.
|
java.lang.String |
getManagerName() |
CacheMXBean |
getMBean() |
MnodeStore |
getMnodeStore() |
java.lang.String |
getName()
Returns the name of the cache.
|
ExtCacheEntry |
getStatCacheEntry(java.lang.Object key) |
CacheStatistics |
getStatistics()
Returns the CacheStatistics for this cache.
|
Status |
getStatus() |
long |
getValueHash(java.lang.Object value) |
java.lang.Object |
invokeEntryProcessor(java.lang.Object key,
Cache.EntryProcessor entryProcessor) |
boolean |
isBackup() |
boolean |
isClosed()
Returns true if the cache is closed
|
boolean |
isDataAvailable(long valueDataId,
long valueDataTime) |
boolean |
isTriplicate() |
java.util.Iterator<Cache.Entry<K,V>> |
iterator() |
java.util.concurrent.Future<V> |
load(K key) |
java.util.concurrent.Future<java.util.Map<K,? extends V>> |
loadAll(java.util.Set<? extends K> keys) |
boolean |
loadData(long valueDataId,
long valueDataTime,
WriteStream os) |
java.lang.Object |
peek(java.lang.Object key)
Returns the object with the given key without checking the backing store.
|
ExtCacheEntry |
peekExtCacheEntry(java.lang.Object key)
Returns the cache entry for the object with the given key.
|
void |
put(K key,
V value)
Puts a new item in the cache.
|
ExtCacheEntry |
put(java.lang.Object key,
java.io.InputStream is,
long accessedExpireTimeout,
long modifiedExpireTimeout)
Puts a new item in the cache with a custom idle
timeout (used for sessions).
|
ExtCacheEntry |
put(java.lang.Object key,
java.io.InputStream is,
long accessedExpireTimeout,
long modifiedExpireTimeout,
int flags)
Puts a new item in the cache with a custom idle
timeout (used for sessions).
|
ExtCacheEntry |
put(java.lang.Object key,
java.io.InputStream is,
long accessedExpireTimeout,
long modifiedExpireTimeout,
long lastAccessTime,
long lastModifiedTime)
Puts a new item in the cache with a custom idle
timeout (used for sessions).
|
void |
putAll(java.util.Map<? extends K,? extends V> map)
Puts each item in the map into the cache.
|
boolean |
putIfAbsent(java.lang.Object key,
java.lang.Object value) |
boolean |
putIfNew(java.lang.Object key,
MnodeUpdate update,
java.io.InputStream is)
Updates the cache if the old version matches the current value.
|
boolean |
registerCacheEntryListener(CacheEntryListener<? super K,? super V> listener,
boolean requireOldValue,
CacheEntryEventFilter<? super K,? super V> filter,
boolean synchronous)
Adds a listener to the cache.
|
boolean |
remove(java.lang.Object key)
Removes the entry from the cache.
|
boolean |
remove(java.lang.Object key,
java.lang.Object oldValue)
Removes the entry from the cache.
|
void |
removeAll() |
void |
removeAll(java.util.Set<? extends K> keys) |
boolean |
replace(java.lang.Object key,
java.lang.Object value) |
boolean |
replace(java.lang.Object key,
java.lang.Object oldValue,
java.lang.Object value) |
DataStore.DataItem |
saveData(StreamSource source,
int length) |
void |
start() |
void |
stop() |
java.lang.String |
toString() |
boolean |
unregisterCacheEntryListener(CacheEntryListener listener)
Removes a listener from the cache.
|
<T> T |
unwrap(java.lang.Class<T> cl) |
public CacheImpl(CacheManagerImpl localManager, java.lang.String name, java.lang.String managerName, java.lang.String guid, CacheConfig config)
public java.lang.String getName()
public java.lang.String getManagerName()
public CacheManager getCacheManager()
getCacheManager
in interface Cache<K,V>
public java.lang.String getGuid()
public CacheConfig getConfig()
public CacheHandle getCacheHandle()
public long getExpireTimeout()
public long getIdleTimeout()
public long getIdleTimeoutWindow()
public long getLeaseTimeout()
public long getLocalReadTimeout()
public CacheImpl createIfAbsent()
public java.lang.Object peek(java.lang.Object key)
public HashKey getKeyHash(java.lang.Object key)
public V get(java.lang.Object key)
public boolean get(java.lang.Object key, java.io.OutputStream os) throws java.io.IOException
get
in interface ByteStreamCache
java.io.IOException
public ExtCacheEntry getExtCacheEntry(java.lang.Object key)
getExtCacheEntry
in interface ByteStreamCache
getExtCacheEntry
in interface ObjectCache<K,V>
public ExtCacheEntry getExtCacheEntry(HashKey key)
public ExtCacheEntry peekExtCacheEntry(java.lang.Object key)
peekExtCacheEntry
in interface ByteStreamCache
public ExtCacheEntry getStatCacheEntry(java.lang.Object key)
getStatCacheEntry
in interface ObjectCache<K,V>
public Cache.Entry getCacheEntry(java.lang.Object key)
public ExtCacheEntry put(java.lang.Object key, java.io.InputStream is, long accessedExpireTimeout, long modifiedExpireTimeout, int flags) throws java.io.IOException
put
in interface ByteStreamCache
key
- the key of the item to putis
- the value of the item to putidleTimeout
- the idle timeout for the itemflags
- the flags value (for memcache)java.io.IOException
public ExtCacheEntry put(java.lang.Object key, java.io.InputStream is, long accessedExpireTimeout, long modifiedExpireTimeout) throws java.io.IOException
put
in interface ByteStreamCache
key
- the key of the item to putis
- the value of the item to putidleTimeout
- the idle timeout for the itemjava.io.IOException
public ExtCacheEntry put(java.lang.Object key, java.io.InputStream is, long accessedExpireTimeout, long modifiedExpireTimeout, long lastAccessTime, long lastModifiedTime) throws java.io.IOException
put
in interface ByteStreamCache
key
- the key of the item to putis
- the value of the item to putidleTimeout
- the idle timeout for the itemjava.io.IOException
public java.lang.Object getAndPut(java.lang.Object key, java.lang.Object value)
public boolean compareVersionAndPut(java.lang.Object key, long version, java.lang.Object value)
compareVersionAndPut
in interface ObjectCache<K,V>
key
- the key to compareversion
- the version of the old value, returned by getEntryvalue
- the new valuepublic boolean putIfNew(java.lang.Object key, MnodeUpdate update, java.io.InputStream is) throws java.io.IOException
putIfNew
in interface ByteStreamCache
key
- the key to compareversion
- the hash of the old version, returned by getEntryinputStream
- the new valuejava.io.IOException
public boolean putIfAbsent(java.lang.Object key, java.lang.Object value) throws CacheException
putIfAbsent
in interface Cache<K,V>
CacheException
public boolean replace(java.lang.Object key, java.lang.Object oldValue, java.lang.Object value) throws CacheException
replace
in interface Cache<K,V>
CacheException
public boolean replace(java.lang.Object key, java.lang.Object value) throws CacheException
replace
in interface Cache<K,V>
CacheException
public java.lang.Object getAndReplace(java.lang.Object key, java.lang.Object value) throws CacheException
getAndReplace
in interface Cache<K,V>
CacheException
public boolean remove(java.lang.Object key)
public boolean remove(java.lang.Object key, java.lang.Object oldValue)
public java.lang.Object getAndRemove(java.lang.Object key) throws CacheException
getAndRemove
in interface Cache<K,V>
CacheException
public boolean compareAndRemove(java.lang.Object key, long version)
compareAndRemove
in interface ByteStreamCache
compareAndRemove
in interface ObjectCache<K,V>
public ExtCacheEntry getLiveCacheEntry(java.lang.Object key)
protected DistCacheEntry getDistCacheEntry(java.lang.Object key)
protected final DistCacheEntry getDistCacheEntry(HashKey key)
public java.util.Map<K,V> getAll(java.util.Set<? extends K> keys)
public boolean registerCacheEntryListener(CacheEntryListener<? super K,? super V> listener, boolean requireOldValue, CacheEntryEventFilter<? super K,? super V> filter, boolean synchronous)
registerCacheEntryListener
in interface Cache<K,V>
public boolean unregisterCacheEntryListener(CacheEntryListener listener)
unregisterCacheEntryListener
in interface Cache<K,V>
public CacheStatistics getStatistics()
getStatistics
in interface Cache<K,V>
public void putAll(java.util.Map<? extends K,? extends V> map)
public boolean containsKey(java.lang.Object key)
containsKey
in interface Cache<K,V>
key
- public boolean isBackup()
public boolean isTriplicate()
public HashKey getCacheKey()
protected java.lang.Object cacheLoader(java.lang.Object key)
public boolean isClosed()
ObjectCache
isClosed
in interface ObjectCache<K,V>
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public boolean loadData(long valueDataId, long valueDataTime, WriteStream os) throws java.io.IOException
java.io.IOException
public DataStore.DataItem saveData(StreamSource source, int length) throws java.io.IOException
java.io.IOException
public boolean isDataAvailable(long valueDataId, long valueDataTime)
public byte[] getKeyHash(java.lang.String name)
public long getValueHash(java.lang.Object value)
public MnodeStore getMnodeStore()
public DataStore getDataStore()
public CacheMXBean getMBean()
public Configuration<K,V> getConfiguration()
getConfiguration
in interface Cache<K,V>
public java.lang.Object invokeEntryProcessor(java.lang.Object key, Cache.EntryProcessor entryProcessor)
invokeEntryProcessor
in interface Cache<K,V>
public java.util.concurrent.Future<V> load(K key) throws CacheException
load
in interface Cache<K,V>
CacheException
public java.util.concurrent.Future<java.util.Map<K,? extends V>> loadAll(java.util.Set<? extends K> keys) throws CacheException
loadAll
in interface Cache<K,V>
CacheException
public void removeAll(java.util.Set<? extends K> keys)
public void removeAll() throws CacheException
removeAll
in interface Cache<K,V>
CacheException
public java.util.Iterator<Cache.Entry<K,V>> iterator()
public Status getStatus()
getStatus
in interface CacheLifecycle
public void start() throws CacheException
start
in interface CacheLifecycle
CacheException
public void stop() throws CacheException
stop
in interface CacheLifecycle
CacheException
public java.lang.String toString()
toString
in class java.lang.Object