类 DefaultContextCache
- java.lang.Object
- org.springframework.test.context.cache.DefaultContextCache
- 所有已实现的接口:
ContextCache
public class DefaultContextCache extends Object implements ContextCache
Default implementation of theContextCacheAPI.Uses a synchronized
Mapconfigured with a maximum size and a least recently used (LRU) eviction policy to cacheApplicationContextinstances.The maximum size may be supplied as a constructor argument or set via a system property or Spring property named
spring.test.context.cache.maxSize.- 从以下版本开始:
- 2.5
- 作者:
- Sam Brannen, Juergen Hoeller
- 另请参阅:
ContextCacheUtils.retrieveMaxCacheSize()
字段概要
从接口继承的字段 org.springframework.test.context.cache.ContextCache
CONTEXT_CACHE_LOGGING_CATEGORY, DEFAULT_MAX_CONTEXT_CACHE_SIZE, MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME
构造器概要
构造器 构造器 说明 DefaultContextCache()Create a newDefaultContextCacheusing the maximum cache size obtained viaContextCacheUtils.retrieveMaxCacheSize().DefaultContextCache(int maxSize)Create a newDefaultContextCacheusing the supplied maximum cache size.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidclear()Clear all contexts from the cache, clearing context hierarchy information as well.voidclearStatistics()Clear hit and miss count statistics for the cache (i.e., reset counters to zero).booleancontains(MergedContextConfiguration key)Determine whether there is a cached context for the given key.ApplicationContextget(MergedContextConfiguration key)Obtain a cachedApplicationContextfor the given key.intgetHitCount()Get the overall hit count for this cache.intgetMaxSize()Get the maximum size of this cache.intgetMissCount()Get the overall miss count for this cache.intgetParentContextCount()Determine the number of parent contexts currently tracked within the cache.voidlogStatistics()Log the statistics for thisContextCacheatDEBUGlevel using the "org.springframework.test.context.cache" logging category.voidput(MergedContextConfiguration key, ApplicationContext context)Explicitly add anApplicationContextinstance to the cache under the given key, potentially honoring a custom eviction policy.voidremove(MergedContextConfiguration key, DirtiesContext.HierarchyMode hierarchyMode)Remove the context with the given key from the cache and explicitly close it if it is an instance ofConfigurableApplicationContext.voidreset()Reset all state maintained by this cache including statistics.intsize()Determine the number of contexts currently stored in the cache.StringtoString()Generate a text string containing the implementation type of this cache and its statistics.
构造器详细资料
DefaultContextCache
public DefaultContextCache()
Create a newDefaultContextCacheusing the maximum cache size obtained viaContextCacheUtils.retrieveMaxCacheSize().- 从以下版本开始:
- 4.3
- 另请参阅:
DefaultContextCache(int),ContextCacheUtils.retrieveMaxCacheSize()
DefaultContextCache
public DefaultContextCache(int maxSize)
Create a newDefaultContextCacheusing the supplied maximum cache size.- 参数:
maxSize- the maximum cache size- 抛出:
IllegalArgumentException- if the suppliedmaxSizevalue is not positive- 从以下版本开始:
- 4.3
- 另请参阅:
DefaultContextCache()
方法详细资料
contains
public boolean contains(MergedContextConfiguration key)
Determine whether there is a cached context for the given key.- 指定者:
contains在接口中ContextCache- 参数:
key- the context key (nevernull)- 返回:
trueif the cache contains a context with the given key
get
@Nullable public ApplicationContext get(MergedContextConfiguration key)
Obtain a cachedApplicationContextfor the given key.- 指定者:
get在接口中ContextCache- 参数:
key- the context key (nevernull)- 返回:
- the corresponding
ApplicationContextinstance, ornullif not found in the cache - 另请参阅:
ContextCache.remove(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
put
public void put(MergedContextConfiguration key, ApplicationContext context)
Explicitly add anApplicationContextinstance to the cache under the given key, potentially honoring a custom eviction policy.- 指定者:
put在接口中ContextCache- 参数:
key- the context key (nevernull)context- theApplicationContextinstance (nevernull)
remove
public void remove(MergedContextConfiguration key, @Nullable DirtiesContext.HierarchyMode hierarchyMode)
Remove the context with the given key from the cache and explicitly close it if it is an instance ofConfigurableApplicationContext.Generally speaking, this method should be called to properly evict a context from the cache (e.g., due to a custom eviction policy) or if the state of a singleton bean has been modified, potentially affecting future interaction with the context.
In addition, the semantics of the supplied
HierarchyModemust be honored. See the Javadoc forDirtiesContext.HierarchyModefor details.- 指定者:
remove在接口中ContextCache- 参数:
key- the context key; nevernullhierarchyMode- the hierarchy mode; may benullif the context is not part of a hierarchy
size
public int size()
Determine the number of contexts currently stored in the cache.If the cache contains more than
Integer.MAX_VALUEelements, this method must returnInteger.MAX_VALUE.- 指定者:
size在接口中ContextCache
getMaxSize
public int getMaxSize()
Get the maximum size of this cache.
getParentContextCount
public int getParentContextCount()
Determine the number of parent contexts currently tracked within the cache.- 指定者:
getParentContextCount在接口中ContextCache
getHitCount
public int getHitCount()
Get the overall hit count for this cache.A hit is any access to the cache that returns a non-null context for the queried key.
- 指定者:
getHitCount在接口中ContextCache
getMissCount
public int getMissCount()
Get the overall miss count for this cache.A miss is any access to the cache that returns a
nullcontext for the queried key.- 指定者:
getMissCount在接口中ContextCache
reset
public void reset()
Reset all state maintained by this cache including statistics.- 指定者:
reset在接口中ContextCache- 另请参阅:
ContextCache.clear(),ContextCache.clearStatistics()
clear
public void clear()
Clear all contexts from the cache, clearing context hierarchy information as well.- 指定者:
clear在接口中ContextCache
clearStatistics
public void clearStatistics()
Clear hit and miss count statistics for the cache (i.e., reset counters to zero).- 指定者:
clearStatistics在接口中ContextCache
logStatistics
public void logStatistics()
Log the statistics for thisContextCacheatDEBUGlevel using the "org.springframework.test.context.cache" logging category.The following information should be logged.
- name of the concrete
ContextCacheimplementation - ContextCache.size()
- parent context count
- hit count
- miss count
- any other information useful for monitoring the state of this cache
- 指定者:
logStatistics在接口中ContextCache
- name of the concrete
toString
public String toString()
Generate a text string containing the implementation type of this cache and its statistics.The string returned by this method contains all information required for compliance with the contract for
logStatistics().