Package cn.dinodev.spring.commons.bean
Class BeanSafeCache<T>
java.lang.Object
cn.dinodev.spring.commons.bean.BeanSafeCache<T>
- Author:
- Cody Lu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptClassLoader(ClassLoader classLoader) Accept the given ClassLoader as cache-safe, even if its classes would not qualify as cache-safe in this CachedIntrospectionResults class.voidclearClassLoader(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.Retrieve a cached infofor the given target class. Retrieve a cached infofor the given target class. booleanisClassLoaderAccepted(ClassLoader classLoader) Check whether this CachedIntrospectionResults class is configured to accept the given ClassLoader.Associates the specified value with the specified key in this cache.remove the specified key in this cache.
-
Constructor Details
-
BeanSafeCache
public BeanSafeCache()
-
-
Method Details
-
acceptClassLoader
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
acceptClassLoadercall at application startup should be paired with aclearClassLoader(java.lang.ClassLoader)call at application shutdown.- Parameters:
classLoader- the ClassLoader to accept
-
clearClassLoader
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
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
Retrieve a cached infofor the given target class. - Parameters:
beanClass- the target class to introspect- Returns:
- the resulting cached info
(never null)
-
getOrElse
Retrieve a cached infofor the given target class. - Parameters:
beanClass- the target class to introspect- Returns:
- the resulting cached info
(never null)
-
put
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
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.
-