com.vaadin.flow.internal.
Class ReflectionCache<C,T>
Type Parameters:
C
- the class types that are used as the cache keys
T
- the cached value type
A thread-safe cache for the result of doing some reflection lookup based on a class. Cached values never expire since it's assumed that the there is a finite number of classes for which reflection results are used.
For internal use only. May be renamed or removed in a future release.
Since:
1.0
Author:
Vaadin Ltd
-
Constructor Summary
ConstructorsConstructorDescriptionReflectionCache
(SerializableFunction<Class<C>, T> valueProvider) Creates a new reflection cache with the given value provider.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Registration
addClearAllAction
(Runnable action) Adds an action that will be run when all reflection caches are cleared.
void
clear()
Removes all mappings from this cache.
static void
clearAll()
Clears all mappings from all reflection caches and related resources.
boolean
Checks whether this cache contains an entry for the given type.
Gets a cached value.
-
Constructor Details
-
ReflectionCache
Creates a new reflection cache with the given value provider. The value provider will be used to produce a new cached value whenever there is a cache miss. It will be run in a context where no
CurrentInstance
is available to prevent accidentally caching values that are computed differently depending on external circumstances.Parameters:
valueProvider
- a function that computes the cached value for a class, notnull
-
-
Method Details
-
get
Gets a cached value. If this cache does not contain a value for the key, the value is computed using the configured value provider and the cache is populated with the new value.
Parameters:
type
- the type for which to get reflection resultsReturns:
the reflection results
-
contains
Checks whether this cache contains an entry for the given type.
Parameters:
type
- the type to check forReturns:
true
if there is a mapping for the type,false
if there is no mapping -
clear
public void clear()Removes all mappings from this cache.
-
addClearAllAction
Adds an action that will be run when all reflection caches are cleared.
The actions are held with a weak reference, which typically means that the action will be ignored if the returned registration is garbage collected.
Parameters:
action
- the action to runReturns:
a registration for removing the action
See Also:
-
clearAll
public static void clearAll()Clears all mappings from all reflection caches and related resources.
-