Class InMemoryOAuthClientMetadataCache
java.lang.Object
com.revetsec.oauth.server.InMemoryOAuthClientMetadataCache
- All Implemented Interfaces:
OAuthClientMetadataCache
@ThreadSafe
@CheckReturnValue
public final class InMemoryOAuthClientMetadataCache
extends Object
implements OAuthClientMetadataCache
Bounded single-process optional cache with timed interruptible locking and approximate LRU
eviction. The reused map is private: all access is serialized, entries are evicted before
insertion and every mutation drains its bounded maintenance work. No listener, loader, worker
thread or general map is exposed. There are at most maximumEntries retained records, each
syntax-bounded to a 16384-byte encrypted envelope. Reads/replacements cost bounded local work;
lock waits consume the supplied budget. Expiry/freshness is checked by the core before use, not
asserted by this storage cache. It may evict at any time and has no durability. Sharing one
instance shares only in-process storage; separate factories return separate caches. Applications
may supply a distributed implementation through the metadata policy's cache option.
The raw reused map has only a maintenance capacity target under concurrent writes. This wrapper
supplies the strict entry bound; keep its map private and every access under its budgeted lock.
- Since:
- 1.0.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptioncompareAndSet(@NonNull OAuthClientMetadataCacheKey key, @Nullable String expectedVersion, @Nullable OAuthClientMetadataCacheEntry replacement, @NonNull Duration remainingBudget) Atomically compares the exact current version/absence and then replaces/removes the carrier at one key.Constructs a fresh cache with the reviewed 128-entry default and no callback or thread startup.fromMaximumEntries(@NonNull Integer maximumEntries) Constructs a fresh cache with a capacity from 1 through 4096, inclusive.Returns the local retained-entry bound.read(@NonNull OAuthClientMetadataCacheKey key, @NonNull Duration remainingBudget) Reads storage data or a confirmed miss; a hit is not a validated document or fresh200 proof.toString()Returns a fixed description with no stored data.
-
Method Details
-
fromDefaults
Constructs a fresh cache with the reviewed 128-entry default and no callback or thread startup.- Returns:
- the fresh local cache
- Since:
- 1.0.0
-
fromMaximumEntries
public static @NonNull InMemoryOAuthClientMetadataCache fromMaximumEntries(@NonNull Integer maximumEntries) Constructs a fresh cache with a capacity from 1 through 4096, inclusive. This is local capacity across all its keys.- Parameters:
maximumEntries- the entry limit- Returns:
- the fresh local cache
- Throws:
NullPointerException- if maximumEntries is nullIllegalArgumentException- if outside the allowed interval- Since:
- 1.0.0
-
getMaximumEntries
Returns the local retained-entry bound.- Returns:
- the bound
- Since:
- 1.0.0
-
read
public @NonNull Optional<@NonNull OAuthClientMetadataCacheEntry> read(@NonNull OAuthClientMetadataCacheKey key, @NonNull Duration remainingBudget) Reads storage data or a confirmed miss; a hit is not a validated document or fresh200 proof.- Specified by:
readin interfaceOAuthClientMetadataCache- Parameters:
key- the exact bounded addressremainingBudget- the positive remaining budget- Returns:
- the carrier or a confirmed miss
- Since:
- 1.0.0
-
compareAndSet
public @NonNull Boolean compareAndSet(@NonNull OAuthClientMetadataCacheKey key, @Nullable String expectedVersion, @Nullable OAuthClientMetadataCacheEntry replacement, @NonNull Duration remainingBudget) Atomically compares the exact current version/absence and then replaces/removes the carrier at one key. Null expectedVersion requires absence; null replacement removes the matched entry. False changes nothing. Replacement keys must match and replacement versions must be fresh and differ from expectedVersion. A competing write cannot be overwritten using an obsolete version. After eviction/expiry, absence can permit a new insertion; this is not durable historical ordering. A failure may leave a mutation applied. This is optional storage, not credential consumption or a distributed lock; no outcome satisfies a fresh200 requirement.- Specified by:
compareAndSetin interfaceOAuthClientMetadataCache- Parameters:
key- the exact addressexpectedVersion- the canonical comparison version, or null for absencereplacement- the bounded replacement, or null to removeremainingBudget- the positive remaining budget- Returns:
- whether the atomic comparison matched and the operation completed
- Since:
- 1.0.0
-
toString
-