Class InMemoryMcpResponseCache
- All Implemented Interfaces:
McpResponseCache
McpResponseCache.
Entries are partitioned by scope, so the same key in two different scopes never collides.
A non-positive ttlMs passed to put(String, String, Object, long) means the entry never expires.
Size bound / eviction policy:
The cache is bounded at DEFAULT_MAX_ENTRIES total entries (across all scopes combined) by default,
overridable via InMemoryMcpResponseCache(int). Once the cap is reached, inserting one more entry
evicts the single least-recently-used entry (an access via get(String, String), whether a hit
or a still-live entry, counts as a use; an expired-and-evicted-on-read entry does not) — a bounded default
that never grows unboundedly under sustained cache traffic, without needing every caller to reason about a
capacity setting themselves.
This class is thread-safe (a synchronized LinkedHashMap in access-order/LRU mode).
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum number of entries (across all scopes combined) retained before the least-recently-used entry is evicted to make room for a new one. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.InMemoryMcpResponseCache(int maxEntries) Constructor with an explicit size cap. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.juneau.rest.client.mcp.McpResponseCache
putResult
-
Field Details
-
DEFAULT_MAX_ENTRIES
Default maximum number of entries (across all scopes combined) retained before the least-recently-used entry is evicted to make room for a new one. See the class javadoc's size-bound/eviction-policy note.- See Also:
-
-
Constructor Details
-
InMemoryMcpResponseCache
public InMemoryMcpResponseCache()Constructor. Uses the system clock (System.currentTimeMillis()) for TTL expiry andDEFAULT_MAX_ENTRIESas the size cap. -
InMemoryMcpResponseCache
Constructor with an explicit size cap. Uses the system clock (System.currentTimeMillis()) for TTL expiry.- Parameters:
maxEntries- The maximum number of entries (across all scopes combined) retained before the least-recently-used entry is evicted. Must be positive.
-
-
Method Details
-
get
Description copied from interface:McpResponseCacheLooks up a cached value.- Specified by:
getin interfaceMcpResponseCache- Parameters:
scope- The cache-scope partition key. Must not benull .key- The cache key (typically method + canonical params). Must not benull .- Returns:
- The cached value, or
Optional.empty()if absent or expired.
-
put
Description copied from interface:McpResponseCacheStores a value.- Specified by:
putin interfaceMcpResponseCache- Parameters:
scope- The cache-scope partition key. Must not benull .key- The cache key (typically method + canonical params). Must not benull .value- The value to cache. Must not benull .ttlMs- The time-to-live in milliseconds. A value<= 0means the entry never expires.
-
clear
Description copied from interface:McpResponseCacheRemoves all cached entries across all scopes.- Specified by:
clearin interfaceMcpResponseCache
-