|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.test.context.ContextCache
class ContextCache
Cache for Spring ApplicationContexts
in a test environment.
Maintains a cache of contexts
by
serializable
key. This has significant performance
benefits if initializing the context would take time. While initializing a
Spring context itself is very quick, some beans in a context, such as a
LocalSessionFactoryBean
for working with Hibernate, may take some time to initialize. Hence it often
makes sense to perform that initialization once.
Field Summary | |
---|---|
private java.util.Map<java.lang.String,ApplicationContext> |
contextKeyToContextMap
Map of context keys to Spring ApplicationContext instances. |
private int |
hitCount
|
private int |
missCount
|
Constructor Summary | |
---|---|
ContextCache()
|
Method Summary | |
---|---|
(package private) void |
clear()
Clears all contexts from the cache. |
(package private) void |
clearStatistics()
Clears hit and miss count statistics for the cache (i.e., resets counters to zero). |
(package private) boolean |
contains(java.lang.String key)
Return whether there is a cached context for the given key. |
(package private) ApplicationContext |
get(java.lang.String key)
Obtain a cached ApplicationContext for the given key. |
(package private) int |
getHitCount()
Get the overall hit count for this cache. |
(package private) int |
getMissCount()
Get the overall miss count for this cache. |
private void |
incrementHitCount()
Increment the hit count by one. |
private void |
incrementMissCount()
Increment the miss count by one. |
(package private) void |
put(java.lang.String key,
ApplicationContext context)
Explicitly add a ApplicationContext instance to the cache under the given key. |
(package private) ApplicationContext |
remove(java.lang.String key)
Remove the context with the given key. |
(package private) void |
setDirty(java.lang.String key)
Mark the context with the given key as dirty, effectively removing the context from the cache and explicitly
closing it if
it is an instance of ConfigurableApplicationContext . |
(package private) int |
size()
Determine the number of contexts currently stored in the cache. |
java.lang.String |
toString()
Generates a text string, which contains the size as well
as the hit and miss counts. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final java.util.Map<java.lang.String,ApplicationContext> contextKeyToContextMap
private int hitCount
private int missCount
Constructor Detail |
---|
ContextCache()
Method Detail |
---|
void clear()
void clearStatistics()
boolean contains(java.lang.String key)
key
- the context key (never null
)ApplicationContext get(java.lang.String key)
The hit
and miss
counts will be updated accordingly.
key
- the context key (never null
)
null
if not found in the cache.remove(java.lang.String)
private void incrementHitCount()
private void incrementMissCount()
null
context for a queried key.
int getHitCount()
int getMissCount()
null
context for a
queried key.
void put(java.lang.String key, ApplicationContext context)
key
- the context key (never null
)context
- the ApplicationContext instance (never null
)ApplicationContext remove(java.lang.String key)
key
- the context key (never null
)
null
if not found in the cache.setDirty(java.lang.String)
void setDirty(java.lang.String key)
removing
the context from the cache and explicitly
closing
it if
it is an instance of ConfigurableApplicationContext
.
Generally speaking, you would only call this method only if you change the state of a singleton bean, potentially affecting future interaction with the context.
key
- the context key (never null
)remove(java.lang.String)
int size()
public java.lang.String toString()
size
as well
as the hit
and miss
counts.
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |