public class Cache extends Object
PersistingElements.getCache() within the using thread.getMaxElementsInCache()).
Cached elements are removed as soon as they have not been accessed since a certain amount of time (see getTimeToLiveSeconds()).getTimeToLiveSeconds()), they are dropped.| Modifier and Type | Method and Description |
|---|---|
protected void |
checkState() |
protected void |
close()
Closes the cache.
|
protected void |
finalize() |
static Cache |
findCache(Thread thread) |
static Cache |
getCache()
Gives a cache to the current thread.
|
PersistingElement |
getKnownPersistingElement(String fullIdentifier)
Finds an element in the cache according to its full identifier.
|
PersistingElement |
getKnownPersistingElement(String identifier,
Class<? extends PersistingElement> clazz)
Finds an element in the cache according to its identifier.
|
static int |
getMaxElementsInCache()
The maximum number of elements that can be kept in a (per-thread) cache (10 000 by default).
|
static int |
getPeriodBetweenCacheCleanupMS()
The time between two cache cleanups (1s by default).
|
static String |
getThreadId(Thread thread)
A string identifier for the thread.
|
static int |
getTimeToLiveSeconds()
Time during which a element is kept in the cache (10s by default).
|
protected boolean |
isActive()
Whether this cache actually caches.
|
boolean |
isClosed()
Checks if this cache can be used or not.
|
void |
register(PersistingElement element)
Registers an element in the cache.
|
void |
reset()
Clears the cache.
|
protected void |
setActive(boolean active)
Making it possible to disable this cache for test purpose.
|
static void |
setMaxElementsInCache(int maxElementsInCache)
Sets the maximum number of elements that can be kept in a (per-thread) cache.
|
static void |
setPeriodBetweenCacheCleanupMS(int periodBetweenCacheCleanupMS)
The time between two cache cleanups.
|
static void |
setTimeToLiveSeconds(int timeToLiveSeconds)
Sets time during which a element is kept in the cache.
|
int |
size()
The size of the cache.
|
void |
unregister(PersistingElement element)
Removes an element in the cache.
|
void |
unregister(String fullIdentifier)
Removes an element in the cache given by its full identifier.
|
public static int getTimeToLiveSeconds()
public static void setTimeToLiveSeconds(int timeToLiveSeconds)
timeToLiveSeconds - time to live in secondspublic static int getMaxElementsInCache()
public static void setMaxElementsInCache(int maxElementsInCache)
public static int getPeriodBetweenCacheCleanupMS()
public static void setPeriodBetweenCacheCleanupMS(int periodBetweenCacheCleanupMS)
periodBetweenCacheCleanupMS - period between two cache cleanups in millisecondspublic static Cache getCache()
protected boolean isActive()
protected void setActive(boolean active)
active - protected void checkState()
public void register(PersistingElement element) throws IllegalStateException
setTimeToLiveSeconds(int)).setMaxElementsInCache(int))element - the element to be cached (during getTimeToLiveSeconds())IllegalStateException - in case this thread is not the thread for this cachepublic void unregister(PersistingElement element) throws IllegalStateException
setTimeToLiveSeconds(int)).element - the element to be uncachedIllegalStateException - in case this thread is not the thread for this cachepublic void unregister(String fullIdentifier) throws IllegalStateException
setTimeToLiveSeconds(int)).fullIdentifier - the full id of the element to be uncachedIllegalStateException - in case this thread is not the thread for this cachepublic PersistingElement getKnownPersistingElement(String fullIdentifier)
setTimeToLiveSeconds(int)).fullIdentifier - the full identifier of the element to be cached; null if not foundIllegalStateException - in case this thread is not the thread for this cachePersistingElement.getFullIdentifier()public PersistingElement getKnownPersistingElement(String identifier, Class<? extends PersistingElement> clazz)
setTimeToLiveSeconds(int)).identifier - the full identifier of the element to be cached; null if not foundclazz - the class that the element instantiates (see Object.getClass(); null if not foundIllegalStateException - in case this thread is not the thread for this cachePersistingElement.getIdentifier()public int size()
public void reset()
public boolean isClosed()
close()protected void close()
isClosed()Copyright © 2016. All Rights Reserved.