public interface Cache<K extends Serializable,V extends Serializable> extends Map<K,V>
If the cache does grow too large, objects will be removed such that those that are accessed least frequently are removed first. Because expiration happens automatically, the cache makes no guarantee as to how long an object will remain in cache after it is put in.
Optionally, a maximum lifetime for all objects can be specified. In that case, objects will be deleted from cache after that amount of time, even if they are frequently accessed. This feature is useful if objects put in cache represent data that should be periodically refreshed; for example, information from a database.
All cache operations are thread safe.
Note that neither keys or values can be null; A NullPointerException
will be thrown attempting to place or retrieve null values in to the cache.
Cacheable
Modifier and Type | Method and Description |
---|---|
long |
getCacheHits()
Returns the number of cache hits.
|
long |
getCacheMisses()
Returns the number of cache misses.
|
int |
getCacheSize()
Returns the size of the cache contents in bytes.
|
long |
getMaxCacheSize()
Returns the maximum size of the cache in bytes.
|
long |
getMaxLifetime()
Returns the maximum number of milliseconds that any object can live
in cache.
|
String |
getName()
Returns the name of the cache.
|
void |
setMaxCacheSize(int maxSize)
Sets the maximum size of the cache in bytes.
|
void |
setMaxLifetime(long maxLifetime)
Sets the maximum number of milliseconds that any object can live
in cache.
|
void |
setName(String name)
Sets the name of the cache
|
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
String getName()
void setName(String name)
name
- the name of the cachelong getMaxCacheSize()
void setMaxCacheSize(int maxSize)
Note: If using the Hazelcast clustering plugin, this will not take effect until the next time the cache is created
maxSize
- the maximum size of the cache in bytes.long getMaxLifetime()
void setMaxLifetime(long maxLifetime)
Note: If using the Hazelcast clustering plugin, this will not take effect until the next time the cache is created
maxLifetime
- the maximum number of milliseconds before objects are expired.int getCacheSize()
long getCacheHits()
Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient.
long getCacheMisses()
Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient.
Copyright © 2003–2019 Ignite Realtime. All rights reserved.