public static final class CacheManager.Cache extends java.lang.Object
Created by the CacheManager, it is the main interface for configuring and accessing information for a named cache.
When created, the default cache size is unlimited.
Modifier and Type | Method and Description |
---|---|
void |
addClass(java.lang.Class<?> klass)
Associate the given class to a cache.
|
void |
disable()
Disable cache.
|
void |
enable()
Enable cache.
|
long |
flush(long numberObjects)
Flush a cache.
|
long |
getCacheSizeBytes()
Return the cache size in bytes.
|
int |
getCacheUtilization()
Return the amount of cache used as a percent.
|
java.lang.Iterable<java.lang.Class<?>> |
getClasses()
Return all known classes associated with this cache.
|
int |
getMemoryUtilization()
Return the amount of shared memory used as a percent.
|
java.lang.String |
getName()
Return the name of the cache.
|
long |
getNumberInstances()
Return the number of instances currently cached.
|
boolean |
isDisabled()
Return if the cache is currently disabled.
|
void |
setSizeBytes(long size)
Set the size of the cache in bytes.
|
void |
setSizePercent(int percent)
Set the size of the cache as a percentage.
|
public void addClass(java.lang.Class<?> klass) throws ManagedClassError, CacheManager.CacheDestroyed
If the class is already associated with a named cache, it will be removed from that cache, and added to this one. If it is already associated with this cache, no changes are made.
klass
- Managed class to add.ManagedClassError
- Thrown if klass
is not Managed.CacheManager.CacheDestroyed
- This cache instance no longer exists.public void setSizeBytes(long size) throws java.lang.IllegalArgumentException, CacheManager.CacheDestroyed
The system cache flusher asynchronously attempts to keep memory utilization at or below this level for objects in this cache. Note that this is not a strict size limit; object sizes will be estimated, and the flusher may run infrequently, allowing the cache to exceed the size setting.
size
- size of cache in bytes.java.lang.IllegalArgumentException
- The size is negative or is greater than the shared memory that
is available.CacheManager.CacheDestroyed
- This cache instance no longer exists.public void setSizePercent(int percent) throws CacheManager.CacheDestroyed
A decimal number between 1 and 100. Indicates the maximum percentage of shared memory within the node to be used for this named cache.
If a percent of 100 is given, the cache will have no limit.
percent
- Percent of shared memory to use for this cache.java.lang.IllegalArgumentException
- An invalid percent was passed in.CacheManager.CacheDestroyed
- This cache instance no longer exists.public void disable() throws CacheManager.CacheDestroyed
This disables further caching of objects. The flusher will asynchronously remove objects if the cache utilization is greater than the size, otherwise the currently cached instances will remain. If the cache is already disabled, no action is taken.
CacheManager.CacheDestroyed
- This cache instance no longer exists.public void enable() throws CacheManager.CacheDestroyed
Enable caching of objects using the current configuration of this named cache. If the cache is already enabled, no action is taken.
CacheManager.CacheDestroyed
- This cache instance no longer exists.public long flush(long numberObjects) throws java.lang.IllegalArgumentException, CacheManager.CacheDestroyed
This immediately flushes instances from the cache until the cache size criteria are met. Note that this may lock a significant number of object instances in the caller's transaction and should be used with care.
Index values are also removed from shared memory when the object is flushed.
numberObjects
- Maximum number of objects to flush. A value
of zero means to flush as many instances as needed.java.lang.IllegalArgumentException
- The numberObjects value is negative.CacheManager.CacheDestroyed
- This cache instance no longer exists.public java.lang.String getName() throws CacheManager.CacheDestroyed
CacheManager.CacheDestroyed
- This cache instance no longer exists.public java.lang.Iterable<java.lang.Class<?>> getClasses() throws CacheManager.CacheDestroyed
Iterable
containing all classes.CacheManager.CacheDestroyed
- This cache instance no longer exists.public boolean isDisabled() throws CacheManager.CacheDestroyed
CacheManager.CacheDestroyed
- This cache instance no longer exists.public long getNumberInstances() throws CacheManager.CacheDestroyed
CacheManager.CacheDestroyed
- This cache instance no longer exists.public long getCacheSizeBytes() throws CacheManager.CacheDestroyed
CacheManager.CacheDestroyed
- This cache instance no longer exists.public int getCacheUtilization() throws CacheManager.CacheDestroyed
If the cache setting has no limit, a value of 0 is returned.
To get the percentage of total shared memory used, use the getMemoryUtilization()
method.
Since the flushing of objects from the cache is asynchronous, values larger than 100 percent can be returned from this method.
CacheManager.CacheDestroyed
- This cache instance no longer exists.public int getMemoryUtilization() throws CacheManager.CacheDestroyed
The percentage of the node's shared memory currently in use by this cache will be calculated and returned. This value will be approximate.
CacheManager.CacheDestroyed
- This cache instance no longer exists.