org.springframework.test.context.cache

Class DefaultContextCache

  • java.lang.Object
    • org.springframework.test.context.cache.DefaultContextCache
    • Method Detail

      • contains

        public boolean contains(MergedContextConfiguration key)
        Determine whether there is a cached context for the given key.
        Specified by:
        contains in interface ContextCache
        Parameters:
        key - the context key (never null)
        Returns:
        true if the cache contains a context with the given key
      • put

        public void put(MergedContextConfiguration key,
                        ApplicationContext context)
        Explicitly add an ApplicationContext instance to the cache under the given key, potentially honoring a custom eviction policy.
        Specified by:
        put in interface ContextCache
        Parameters:
        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.

        Specified by:
        remove in interface ContextCache
        Parameters:
        key - the context key; never null
        hierarchyMode - the hierarchy mode; may be null if 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_VALUE elements, this method must return Integer.MAX_VALUE.

        Specified by:
        size in interface 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.
        Specified by:
        getParentContextCount in interface 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.

        Specified by:
        getHitCount in interface 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.

        Specified by:
        getMissCount in interface ContextCache
      • clear

        public void clear()
        Clear all contexts from the cache, clearing context hierarchy information as well.
        Specified by:
        clear in interface ContextCache
      • clearStatistics

        public void clearStatistics()
        Clear hit and miss count statistics for the cache (i.e., reset counters to zero).
        Specified by:
        clearStatistics in interface ContextCache
      • toString

        public java.lang.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().

        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this cache, including statistics