public final class OHCacheChunkedImpl<K,V> extends Object implements OHCache<K,V>
NEVER_EXPIRE, USE_DEFAULT_EXPIRE_AT| Constructor and Description |
|---|
OHCacheChunkedImpl(OHCacheBuilder<K,V> builder) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addOrReplace(K key,
V old,
V value)
Same as
OHCache.addOrReplace(Object, Object, Object, long) but uses the configured default TTL, if any. |
boolean |
addOrReplace(K key,
V old,
V value,
long expireAt)
Adds key/value if either the key is not present or the existing value matches parameter
old. |
long |
capacity() |
void |
clear()
Removes all entries from the cache.
|
void |
close() |
boolean |
containsKey(K key)
Checks whether an entry for a given key exists.
|
int |
deserializeEntries(ReadableByteChannel channel) |
boolean |
deserializeEntry(ReadableByteChannel channel) |
CloseableIterator<K> |
deserializeKeys(ReadableByteChannel channel) |
long |
freeCapacity() |
V |
get(K key)
Get the value for a given key.
|
EstimatedHistogram |
getBucketHistogram() |
DirectValueAccess |
getDirect(K key)
Returns a closeable byte buffer.
|
DirectValueAccess |
getDirect(K key,
boolean updateLRU)
Like
OHCache.getDirect(Object), but allows skipping the update of LRU stats when updateLRU
is false. |
V |
getWithLoader(K key,
CacheLoader<K,V> loader)
|
V |
getWithLoader(K key,
CacheLoader<K,V> loader,
long timeout,
TimeUnit unit)
|
Future<V> |
getWithLoaderAsync(K key,
CacheLoader<K,V> loader)
Shortcut to call
OHCache.getWithLoader(Object, CacheLoader, long, TimeUnit) using the default entry
time-to-live. |
Future<V> |
getWithLoaderAsync(K key,
CacheLoader<K,V> loader,
long expireAt)
Shortcut to call
OHCache.getWithLoader(Object, CacheLoader, long, TimeUnit) using the default entry
time-to-live. |
int[] |
hashTableSizes() |
CloseableIterator<ByteBuffer> |
hotKeyBufferIterator(int n)
Builds an iterator over all keys returning direct byte buffers.
|
CloseableIterator<K> |
hotKeyIterator(int n)
Builds an iterator over the N most recently used keys returning deserialized objects.
|
CloseableIterator<ByteBuffer> |
keyBufferIterator()
Builds an iterator over all keys returning direct byte buffers.
|
CloseableIterator<K> |
keyIterator()
Builds an iterator over all keys returning deserialized objects.
|
float |
loadFactor() |
long |
memUsed() |
long[] |
perSegmentSizes() |
boolean |
put(K key,
V value)
Same as
OHCache.put(Object, Object, long) but uses the configured default TTL, if any. |
boolean |
put(K key,
V value,
long expireAt)
Adds the key/value.
|
void |
putAll(Map<? extends K,? extends V> m)
This is effectively a shortcut to add all entries in the given map
m. |
boolean |
putIfAbsent(K key,
V value)
Same as
OHCache.putIfAbsent(Object, Object, long) but uses the configured default TTL, if any. |
boolean |
putIfAbsent(K key,
V value,
long expireAt)
Adds the key/value if the key is not present.
|
boolean |
remove(K k)
Remove a single entry for the given key.
|
void |
removeAll(Iterable<K> iterable)
This is effectively a shortcut to remove the entries for all keys given in the iterable
keys. |
void |
resetStatistics() |
int |
segments() |
boolean |
serializeEntry(K key,
WritableByteChannel channel) |
int |
serializeHotNEntries(int n,
WritableByteChannel channel) |
int |
serializeHotNKeys(int n,
WritableByteChannel channel) |
void |
setCapacity(long capacity)
Modify the cache's capacity.
|
long |
size() |
OHCacheStats |
stats() |
String |
toString() |
public OHCacheChunkedImpl(OHCacheBuilder<K,V> builder)
public DirectValueAccess getDirect(K key)
OHCacheDirectValueAccess instance after use.
After closing, you must not call any of the methods of the ByteBuffer
returned by DirectValueAccess.buffer().public DirectValueAccess getDirect(K key, boolean updateLRU)
OHCacheOHCache.getDirect(Object), but allows skipping the update of LRU stats when updateLRU
is false.public boolean containsKey(K key)
OHCachenull via OHCache.get(Object).containsKey in interface OHCache<K,V>key - key of the entry to be retrieved. Must not be null.true if an entry for the given key exists or false if no entry for the requested key existspublic boolean put(K key, V value)
OHCacheOHCache.put(Object, Object, long) but uses the configured default TTL, if any.public boolean put(K key, V value, long expireAt)
OHCacheput in interface OHCache<K,V>key - key of the entry to be added. Must not be null.value - value of the entry to be added. Must not be null.expireAt - timestamp in milliseconds since "epoch" (like System.currentTimeMillis())
when the entry shall expire. Pass OHCache.USE_DEFAULT_EXPIRE_AT for the configured default
time-to-live or OHCache.NEVER_EXPIRE to let it never expire.true, if the entry has been added, false otherwisepublic boolean addOrReplace(K key, V old, V value)
OHCacheOHCache.addOrReplace(Object, Object, Object, long) but uses the configured default TTL, if any.addOrReplace in interface OHCache<K,V>key - key of the entry to be added or replaced. Must not be null.old - if the entry exists, it's serialized value is compared to the serialized value of old
and only replaced, if it matches.value - value of the entry to be added. Must not be null.true on success or false if the existing value does not matcuh oldpublic boolean addOrReplace(K key, V old, V value, long expireAt)
OHCacheold.
If the entry size of key/value exceeds the configured maximum entry length, the old value is removed.addOrReplace in interface OHCache<K,V>key - key of the entry to be added or replaced. Must not be null.old - if the entry exists, it's serialized value is compared to the serialized value of old
and only replaced, if it matches.value - value of the entry to be added. Must not be null.expireAt - timestamp in milliseconds since "epoch" (like System.currentTimeMillis())
when the entry shall expire. Pass OHCache.USE_DEFAULT_EXPIRE_AT for the configured default
time-to-live or OHCache.NEVER_EXPIRE to let it never expire.true on success or false if the existing value does not matcuh oldpublic boolean putIfAbsent(K key, V value)
OHCacheOHCache.putIfAbsent(Object, Object, long) but uses the configured default TTL, if any.putIfAbsent in interface OHCache<K,V>key - key of the entry to be added. Must not be null.value - value of the entry to be added. Must not be null.true on success or false if the key is already present.public boolean putIfAbsent(K key, V value, long expireAt)
OHCacheputIfAbsent in interface OHCache<K,V>key - key of the entry to be added. Must not be null.value - value of the entry to be added. Must not be null.expireAt - timestamp in milliseconds since "epoch" (like System.currentTimeMillis())
when the entry shall expire. Pass OHCache.USE_DEFAULT_EXPIRE_AT for the configured default
time-to-live or OHCache.NEVER_EXPIRE to let it never expire.true on success or false if the key is already present.public boolean remove(K k)
OHCachepublic V getWithLoader(K key, CacheLoader<K,V> loader) throws InterruptedException, ExecutionException
OHCachegetWithLoader in interface OHCache<K,V>key - key of the value to loadloader - loader implementation to usenullInterruptedException - as from the contract of Future.get()ExecutionException - thrown if the CacheLoader.load(Object) implementation threw an error or a
runtime exception occured due to not enough memory for example.public V getWithLoader(K key, CacheLoader<K,V> loader, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
OHCachegetWithLoader in interface OHCache<K,V>key - key of the value to loadloader - loader implementation to usetimeout - timeout value to be passed to Future.get(long, TimeUnit)unit - timeout unit to be passed to Future.get(long, TimeUnit)nullInterruptedException - as from the contract of Future.get()ExecutionException - thrown if the CacheLoader.load(Object) implementation threw an error or a
runtime exception occured due to not enough memory for example.TimeoutException - as from the contract of Future.get(long, TimeUnit)public Future<V> getWithLoaderAsync(K key, CacheLoader<K,V> loader)
OHCacheOHCache.getWithLoader(Object, CacheLoader, long, TimeUnit) using the default entry
time-to-live. Note that the cache has to be configured with an Executor to
schedule the load process.
Note that the future may indicate a failure via it's get methods if the
CacheLoader.load(Object) implementation threw an error or a runtime exception occured due to
not enough memory for example.
getWithLoaderAsync in interface OHCache<K,V>key - key of the value to loadloader - loader implementation to usepublic Future<V> getWithLoaderAsync(K key, CacheLoader<K,V> loader, long expireAt)
OHCacheOHCache.getWithLoader(Object, CacheLoader, long, TimeUnit) using the default entry
time-to-live. Note that the cache has to be configured with an Executor to
schedule the load process.
Note that the future may indicate a failure via it's get methods if the
CacheLoader.load(Object) implementation threw an error or a runtime exception occured due to
not enough memory for example.
getWithLoaderAsync in interface OHCache<K,V>key - key of the value to loadloader - loader implementation to usepublic void clear()
OHCachepublic void setCapacity(long capacity)
OHCacheFuture operations will even allocate in flight, temporary memory - i.e. setting capacity to 0 does not disable the cache, it will continue to work but cannot add more data.
setCapacity in interface OHCache<K,V>public void close()
close in interface Closeableclose in interface AutoCloseablepublic void resetStatistics()
resetStatistics in interface OHCache<K,V>public OHCacheStats stats()
public long freeCapacity()
freeCapacity in interface OHCache<K,V>public float loadFactor()
loadFactor in interface OHCache<K,V>public int[] hashTableSizes()
hashTableSizes in interface OHCache<K,V>public long[] perSegmentSizes()
perSegmentSizes in interface OHCache<K,V>public EstimatedHistogram getBucketHistogram()
getBucketHistogram in interface OHCache<K,V>public CloseableIterator<K> deserializeKeys(ReadableByteChannel channel) throws IOException
deserializeKeys in interface OHCache<K,V>IOExceptionpublic boolean deserializeEntry(ReadableByteChannel channel) throws IOException
deserializeEntry in interface OHCache<K,V>IOExceptionpublic boolean serializeEntry(K key, WritableByteChannel channel) throws IOException
serializeEntry in interface OHCache<K,V>IOExceptionpublic int deserializeEntries(ReadableByteChannel channel) throws IOException
deserializeEntries in interface OHCache<K,V>IOExceptionpublic int serializeHotNEntries(int n,
WritableByteChannel channel)
throws IOException
serializeHotNEntries in interface OHCache<K,V>IOExceptionpublic int serializeHotNKeys(int n,
WritableByteChannel channel)
throws IOException
serializeHotNKeys in interface OHCache<K,V>IOExceptionpublic void putAll(Map<? extends K,? extends V> m)
OHCachem.public void removeAll(Iterable<K> iterable)
OHCachekeys.public CloseableIterator<K> hotKeyIterator(int n)
OHCacheclose() on the returned iterator.
Note: During a rehash, the implementation might return keys twice or not at all.
hotKeyIterator in interface OHCache<K,V>public CloseableIterator<ByteBuffer> hotKeyBufferIterator(int n)
OHCacheByteBuffer after calling any method on the iterator.
You must call close() on the returned iterator.
Note: During a rehash, the implementation might return keys twice or not at all.
hotKeyBufferIterator in interface OHCache<K,V>public CloseableIterator<K> keyIterator()
OHCacheclose() on the returned iterator.
Note: During a rehash, the implementation might return keys twice or not at all.
keyIterator in interface OHCache<K,V>public CloseableIterator<ByteBuffer> keyBufferIterator()
OHCacheByteBuffer after calling any method on the iterator.
You must call close() on the returned iterator.
Note: During a rehash, the implementation might return keys twice or not at all.
keyBufferIterator in interface OHCache<K,V>Copyright © 2014–2021 Robert Stupp, Koeln, Germany, robert-stupp.de. All rights reserved.