Class CachingPropertySource
- All Implemented Interfaces:
PropertySource
PropertySource whose answers can never change after construction.
Every lookup result, hits and misses alike, is cached in a ConcurrentHashMap, so a repeated lookup costs one
map read instead of whatever the delegate does (for example the relaxed environment source tokenizes the name and
probes up to three environment variables).
Contract:
Wrap only sources whose answers cannot change after construction, including their misses.
A wrapped source that answers PropertyLookupResult.missing() once, for any reason, answers it forever.
Never wrap system properties, config files, Spring environments, stores, or any source that can return
missing() without memoizing (for example during a static initializer).
Do not wrap a SensitivePropertySource either: the wrapper hides the redaction marker and keeps secret values in
memory for its lifetime.
Soft cap:
The cache holds at most MAX_ENTRIES names. Once full, new names pass through to the delegate uncached; there
is no eviction, so the first names seen win. The check is not locked: concurrent first lookups can overshoot the cap
by at most the number of racing threads.
Null names:
A null name skips the cache (it cannot hold a null key) and goes to the delegate, so each delegate
keeps its own null behavior.
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum number of names cached by one instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns a property in this property source.static CachingPropertySourceof(PropertySource delegate) Wraps the specified source.
-
Field Details
-
MAX_ENTRIES
The maximum number of names cached by one instance.- See Also:
-
-
Method Details
-
of
Wraps the specified source.- Parameters:
delegate- The source to wrap. Its answers must never change. Must not benull .- Returns:
- A new caching source.
-
get
Description copied from interface:PropertySourceReturns a property in this property source.- Specified by:
getin interfacePropertySource- Parameters:
name- The property name.- Returns:
- The property lookup result:
PropertyLookupResult.missing()if this source does not define the key.PropertyLookupResult.present(Optional)withOptional.empty()if the key exists with a null value.PropertyLookupResult.present(Optional)with a value if the key exists with a non-null value.
-