public final class OHCacheImpl<K,V> extends Object implements OHCache<K,V>
Constructor and Description |
---|
OHCacheImpl(OHCacheBuilder<K,V> builder) |
Modifier and Type | Method and Description |
---|---|
boolean |
addOrReplace(K key,
V old,
V value)
Adds key/value if either the key is not present or the existing value matches parameter
old . |
long |
capacity() |
void |
clear() |
void |
close() |
boolean |
containsKey(K key) |
int |
deserializeEntries(ReadableByteChannel channel) |
boolean |
deserializeEntry(ReadableByteChannel channel) |
CloseableIterator<K> |
deserializeKeys(ReadableByteChannel channel) |
long |
evictedEntries() |
long |
freeCapacity() |
V |
get(K key) |
EstimatedHistogram |
getBucketHistogram() |
DirectValueAccess |
getDirect(K key)
Returns a closeable byte buffer.
|
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) |
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() |
void |
put(K k,
V v)
Adds the key/value.
|
void |
putAll(Map<? extends K,? extends V> m) |
boolean |
putIfAbsent(K k,
V v)
Adds the key/value if the key is not present.
|
void |
remove(K k) |
void |
removeAll(Iterable<K> iterable) |
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() |
public OHCacheImpl(OHCacheBuilder<K,V> builder)
public DirectValueAccess getDirect(K key)
OHCache
DirectValueAccess
instance after use.
After closing, you must not call any of the methods of the ByteBuffer
returned by DirectValueAccess.buffer()
.public boolean containsKey(K key)
containsKey
in interface OHCache<K,V>
public void put(K k, V v)
OHCache
public boolean addOrReplace(K key, V old, V value)
OHCache
old
.
If the entry size of key/value exceeds the configured maximum entry length, the old value is removed.addOrReplace
in interface OHCache<K,V>
public boolean putIfAbsent(K k, V v)
OHCache
putIfAbsent
in interface OHCache<K,V>
public V getWithLoader(K key, CacheLoader<K,V> loader) throws InterruptedException, ExecutionException
getWithLoader
in interface OHCache<K,V>
InterruptedException
ExecutionException
public V getWithLoader(K key, CacheLoader<K,V> loader, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
getWithLoader
in interface OHCache<K,V>
InterruptedException
ExecutionException
TimeoutException
public Future<V> getWithLoaderAsync(K key, CacheLoader<K,V> loader)
getWithLoaderAsync
in interface OHCache<K,V>
public void setCapacity(long capacity)
OHCache
Future 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 Closeable
close
in interface AutoCloseable
public void resetStatistics()
resetStatistics
in interface OHCache<K,V>
public OHCacheStats stats()
public long freeCapacity()
freeCapacity
in interface OHCache<K,V>
public long evictedEntries()
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>
IOException
public boolean deserializeEntry(ReadableByteChannel channel) throws IOException
deserializeEntry
in interface OHCache<K,V>
IOException
public boolean serializeEntry(K key, WritableByteChannel channel) throws IOException
serializeEntry
in interface OHCache<K,V>
IOException
public int deserializeEntries(ReadableByteChannel channel) throws IOException
deserializeEntries
in interface OHCache<K,V>
IOException
public int serializeHotNEntries(int n, WritableByteChannel channel) throws IOException
serializeHotNEntries
in interface OHCache<K,V>
IOException
public int serializeHotNKeys(int n, WritableByteChannel channel) throws IOException
serializeHotNKeys
in interface OHCache<K,V>
IOException
public CloseableIterator<K> hotKeyIterator(int n)
OHCache
close()
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)
OHCache
ByteBuffer
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()
OHCache
close()
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()
OHCache
ByteBuffer
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–2016 Robert Stupp, Koeln, Germany, robert-stupp.de. All rights reserved.