Package net.thevpc.naru.ext.models.cache
Class NaruCacheBaseline
java.lang.Object
net.thevpc.naru.ext.models.cache.NaruCacheBaseline
The last cache identity this session established, persisted between turns.
Identity is scoped to a provider, a model and a caching mode on purpose. A session that switches model, or an endpoint reconfigured from an OpenAI-compatible one to Anthropic, has a baseline that describes a different server's cache entirely; reusing it would claim a hit for a prefix the new provider has never seen. Scoping makes that a cold start rather than a lie.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBumped if the on-disk shape changes in a way older readers cannot handle. -
Constructor Summary
ConstructorsConstructorDescriptionNaruCacheBaseline(String providerName, String modelName, NaruCachingMode cachingMode, List<String> segmentKeys, String cachedResourceId, long resourceExpiresAt, long updatedAt) -
Method Summary
Modifier and TypeMethodDescriptionstatic NaruCacheBaselineempty()static NaruCacheBaselinefromElement(net.thevpc.nuts.elem.NElement e) Reads a baseline back.longlongbooleanisResourceUsable(long now, long safetyMarginMillis) Whether a cached resource id may still be trusted atnow.booleanmatches(String providerName, String modelName, NaruCachingMode mode) Whether this baseline can be compared against a request for the given provider/model/mode.net.thevpc.nuts.elem.NElementwithResource(String resourceId, long expiresAt, long now) withSegmentKeys(List<String> keys) withUpdatedAt(long now)
-
Field Details
-
SCHEMA_VERSION
public static final int SCHEMA_VERSIONBumped if the on-disk shape changes in a way older readers cannot handle.- See Also:
-
-
Constructor Details
-
NaruCacheBaseline
-
-
Method Details
-
empty
-
getProviderName
-
getModelName
-
getCachingMode
-
getSegmentKeys
-
getCachedResourceId
-
getResourceExpiresAt
public long getResourceExpiresAt() -
getUpdatedAt
public long getUpdatedAt() -
matches
Whether this baseline can be compared against a request for the given provider/model/mode. A mismatch on any axis means a cold cache. -
isResourceUsable
public boolean isResourceUsable(long now, long safetyMarginMillis) Whether a cached resource id may still be trusted atnow.An unknown expiry is treated as expired. The alternative is holding a reference to a resource the provider already dropped, which surfaces as an opaque 404 on the next call and costs a round trip to diagnose.
-
withSegmentKeys
-
withResource
-
withUpdatedAt
-
toElement
public net.thevpc.nuts.elem.NElement toElement() -
fromElement
Reads a baseline back. Any structural surprise yieldsempty()rather than an exception: a corrupt cache hint must never cost the user their session, and a cold cache is always a safe answer.
-