|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.googlecode.n_orm.cache.Cache
public class Cache
A cache for temporarily storing PersistingElements.
There is a cache per thread, so that cached elements are thread safe unless explicitly shared across threads.
Only thread owning a cache is allowed to use this cache.
To get a cache, use getCache() within the using thread.
Caches are limited in size (see getMaxElementsInCache()).
Cached elements are removed as soon as they have not been accessed since a certain amount of time (see getTimeToLiveSeconds()).
Caches for dead thread are recycled, but in case they have not been used during a certain amount of time (see getTimeToLiveSeconds()), they are dropped.
| Method Summary | |
|---|---|
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). |
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. |
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
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 findCache(Thread thread)
public static Cache getCache()
public static String getThreadId(Thread thread)
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 cache
public void unregister(PersistingElement element)
throws IllegalStateException
setTimeToLiveSeconds(int)).
element - the element to be uncached
IllegalStateException - 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 found
IllegalStateException - 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 found
IllegalStateException - 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()
protected void finalize()
throws Throwable
finalize in class ObjectThrowable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||