Class BeanSafeCache<T>

java.lang.Object
cn.dinodev.spring.commons.bean.BeanSafeCache<T>

public class BeanSafeCache<T> extends Object
Author:
Cody Lu
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Accept the given ClassLoader as cache-safe, even if its classes would not qualify as cache-safe in this CachedIntrospectionResults class.
    void
    Clear the introspection cache for the given ClassLoader, removing the introspection results for all classes underneath that ClassLoader, and removing the ClassLoader (and its children) from the acceptance list.
    get(Class<?> beanClass)
    Retrieve a cached info for the given target class.
    getOrElse(Class<?> beanClass, Function<Class<?>,? extends T> provider)
    Retrieve a cached info for the given target class.
    boolean
    Check whether this CachedIntrospectionResults class is configured to accept the given ClassLoader.
    put(Class<?> beanClass, T info)
    Associates the specified value with the specified key in this cache.
    remove(Class<?> beanClass)
    remove the specified key in this cache.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BeanSafeCache

      public BeanSafeCache()
  • Method Details

    • acceptClassLoader

      public void acceptClassLoader(@Nullable ClassLoader classLoader)
      Accept the given ClassLoader as cache-safe, even if its classes would not qualify as cache-safe in this CachedIntrospectionResults class.

      This configuration method is only relevant in scenarios where the Spring classes reside in a 'common' ClassLoader (e.g. the system ClassLoader) whose lifecycle is not coupled to the application. In such a scenario, CachedIntrospectionResults would by default not cache any of the application's classes, since they would create a leak in the common ClassLoader.

      Any acceptClassLoader call at application startup should be paired with a clearClassLoader(java.lang.ClassLoader) call at application shutdown.

      Parameters:
      classLoader - the ClassLoader to accept
    • clearClassLoader

      public void clearClassLoader(@Nullable ClassLoader classLoader)
      Clear the introspection cache for the given ClassLoader, removing the introspection results for all classes underneath that ClassLoader, and removing the ClassLoader (and its children) from the acceptance list.
      Parameters:
      classLoader - the ClassLoader to clear the cache for
    • isClassLoaderAccepted

      public boolean isClassLoaderAccepted(ClassLoader classLoader)
      Check whether this CachedIntrospectionResults class is configured to accept the given ClassLoader.
      Parameters:
      classLoader - the ClassLoader to check
      Returns:
      whether the given ClassLoader is accepted
      See Also:
    • get

      public T get(Class<?> beanClass)
      Retrieve a cached info for the given target class.
      Parameters:
      beanClass - the target class to introspect
      Returns:
      the resulting cached info (never null)
    • getOrElse

      public T getOrElse(Class<?> beanClass, Function<Class<?>,? extends T> provider)
      Retrieve a cached info for the given target class.
      Parameters:
      beanClass - the target class to introspect
      Returns:
      the resulting cached info (never null)
    • put

      public T put(Class<?> beanClass, T info)
      Associates the specified value with the specified key in this cache.
      Parameters:
      beanClass -
      info -
      Returns:
      the previous value associated with key, or null if there was no mapping for key.
    • remove

      public T remove(Class<?> beanClass)
      remove the specified key in this cache.
      Parameters:
      beanClass -
      Returns:
      the previous value associated with key, or null if there was no mapping for key.