Class CachingPropertySource

java.lang.Object
org.apache.juneau.commons.settings.CachingPropertySource
All Implemented Interfaces:
PropertySource

public final class CachingPropertySource extends Object implements PropertySource
Memoizing decorator for a 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