类 DefaultContextCache

java.lang.Object
cn.taketoday.test.context.cache.DefaultContextCache
所有已实现的接口:
ContextCache

public class DefaultContextCache extends Object implements ContextCache
Default implementation of the ContextCache API.

Uses a synchronized Map configured with a maximum size and a least recently used (LRU) eviction policy to cache ApplicationContext instances.

The maximum size may be supplied as a constructor argument or set via a system property or Infra property named infra.test.context.cache.maxSize.

从以下版本开始:
4.0
作者:
Sam Brannen, Juergen Hoeller, Harry Yang
另请参阅:
  • 字段详细资料

    • statsLogger

      private static final cn.taketoday.logging.Logger statsLogger
    • contextMap

      private final Map<MergedContextConfiguration,cn.taketoday.context.ApplicationContext> contextMap
      Map of context keys to Infra ApplicationContext instances.
    • hierarchyMap

      Map of parent keys to sets of children keys, representing a top-down tree of context hierarchies. This information is used for determining which subtrees need to be recursively removed and closed when removing a context that is a parent of other contexts.
    • failureCounts

      private final Map<MergedContextConfiguration,Integer> failureCounts
      Map of context keys to context load failure counts.
    • totalFailureCount

      private final AtomicInteger totalFailureCount
    • maxSize

      private final int maxSize
    • hitCount

      private final AtomicInteger hitCount
    • missCount

      private final AtomicInteger missCount
  • 构造器详细资料

  • 方法详细资料

    • contains

      public boolean contains(MergedContextConfiguration key)
      Determine whether there is a cached context for the given key.
      指定者:
      contains 在接口中 ContextCache
      参数:
      key - the context key (never null)
      返回:
      true if the cache contains a context with the given key
    • get

      @Nullable public cn.taketoday.context.ApplicationContext get(MergedContextConfiguration key)
      Obtain a cached ApplicationContext for the given key.

      The hit and miss counts must be updated accordingly.

      指定者:
      get 在接口中 ContextCache
      参数:
      key - the context key (never null)
      返回:
      the corresponding ApplicationContext instance, or null if not found in the cache
      另请参阅:
    • put

      public void put(MergedContextConfiguration key, cn.taketoday.context.ApplicationContext context)
      Explicitly add an ApplicationContext instance to the cache under the given key, potentially honoring a custom eviction policy.
      指定者:
      put 在接口中 ContextCache
      参数:
      key - the context key (never null)
      context - the ApplicationContext instance (never null)
    • 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 of ConfigurableApplicationContext.

      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 HierarchyMode must be honored. See the Javadoc for DirtiesContext.HierarchyMode for details.

      指定者:
      remove 在接口中 ContextCache
      参数:
      key - the context key; never null
      hierarchyMode - the hierarchy mode; may be null if the context is not part of a hierarchy
    • remove

      private void remove(List<MergedContextConfiguration> removedContexts, MergedContextConfiguration key)
    • getFailureCount

      public int getFailureCount(MergedContextConfiguration key)
      Get the failure count for the given key.

      A failure is any attempt to load the ApplicationContext for the given key that results in an exception.

      The default implementation of this method always returns 0. Concrete implementations are therefore highly encouraged to override this method and ContextCache.incrementFailureCount(MergedContextConfiguration) with appropriate behavior. Note that the standard ContextContext implementation in Infra overrides these methods appropriately.

      指定者:
      getFailureCount 在接口中 ContextCache
      参数:
      key - the context key; never null
      另请参阅:
    • incrementFailureCount

      public void incrementFailureCount(MergedContextConfiguration key)
      Increment the failure count for the given key.

      The default implementation of this method does nothing. Concrete implementations are therefore highly encouraged to override this method and ContextCache.getFailureCount(MergedContextConfiguration) with appropriate behavior. Note that the standard ContextContext implementation in Infra overrides these methods appropriately.

      指定者:
      incrementFailureCount 在接口中 ContextCache
      参数:
      key - the context key; never null
      另请参阅:
    • size

      public int size()
      Determine the number of contexts currently stored in the cache.

      If the cache contains more than Integer.MAX_VALUE elements, this method must return Integer.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 null context for the queried key.

      指定者:
      getMissCount 在接口中 ContextCache
    • reset

      public void reset()
      Reset all state maintained by this cache including statistics.
      指定者:
      reset 在接口中 ContextCache
      另请参阅:
    • clear

      public void clear()
      Clear all contexts from the cache, clearing context hierarchy information as well.
      指定者:
      clear 在接口中 ContextCache
    • clearStatistics

      public void clearStatistics()
      Clear hit count and miss count statistics for the cache (i.e., reset counters to zero).
      指定者:
      clearStatistics 在接口中 ContextCache
    • logStatistics

      public void logStatistics()
      Log the statistics for this ContextCache at DEBUG level using the "cn.taketoday.test.context.cache" logging category.

      The following information should be logged.

      指定者:
      logStatistics 在接口中 ContextCache
    • 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().

      覆盖:
      toString 在类中 Object
      返回:
      a string representation of this cache, including statistics