Package net.thevpc.naru.ext.models.cache
Class NaruModelCacheExtension
java.lang.Object
net.thevpc.naru.ext.models.cache.NaruModelCacheExtension
- All Implemented Interfaces:
NaruSessionExtension,net.thevpc.nuts.spi.NComponent
Per-session prompt-cache bookkeeping.
Lives in the session extension slot (ext/model-cache.tson) rather
than in the session's own record, because this is model-layer state about a
remote provider's cache and has no business in the core session format. It
also gets the single-instance-per-session guarantee for free, which is what
lets the update path be a plain method call instead of a lookup dance on
every model turn.
State is keyed by provider, model and caching mode. A session that talks to more than one model would otherwise have one model's cache identity silently invalidate another's.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbaseline(String providerName, String modelName, NaruCachingMode mode) voidclear()voidclearResource(String providerName, String modelName, NaruCachingMode mode) Drop a resource reference without discarding the chain, so the next turn can still reuse the prefix it already proved.voidclose()voidcommit(String providerName, String modelName, NaruCachingMode mode, List<String> segmentKeys, long now) Record the chain this turn actually sent, so the next turn can tell a hit from a miss.voidcommitResource(String providerName, String modelName, NaruCachingMode mode, String resourceId, long expiresAt, List<String> segmentKeys, long now) Associate a stateful cache resource with this target.net.thevpc.nuts.util.NOptional<net.thevpc.nuts.elem.NElement>load(NaruSession session, net.thevpc.nuts.io.NPath file) name()static NaruModelCacheExtensionof(NaruSession session) The instance for a session, or null when the extension was not registered.net.thevpc.nuts.elem.NElementsave(NaruSession session) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.thevpc.naru.api.registry.NaruSessionExtension
contribute, isRelevant, open, order, source, sources
-
Field Details
-
NAME
- See Also:
-
-
Constructor Details
-
NaruModelCacheExtension
public NaruModelCacheExtension()
-
-
Method Details
-
of
The instance for a session, or null when the extension was not registered.Callers treat null as "no cache support configured" and fall back to full resend, which is the correct behaviour rather than an error.
-
baseline
-
commit
public void commit(String providerName, String modelName, NaruCachingMode mode, List<String> segmentKeys, long now) Record the chain this turn actually sent, so the next turn can tell a hit from a miss. -
commitResource
public void commitResource(String providerName, String modelName, NaruCachingMode mode, String resourceId, long expiresAt, List<String> segmentKeys, long now) Associate a stateful cache resource with this target. Used by providers whose cache lives in a separate server-side resource. -
clearResource
Drop a resource reference without discarding the chain, so the next turn can still reuse the prefix it already proved. -
clear
public void clear() -
name
- Specified by:
namein interfaceNaruSessionExtension
-
load
public net.thevpc.nuts.util.NOptional<net.thevpc.nuts.elem.NElement> load(NaruSession session, net.thevpc.nuts.io.NPath file) - Specified by:
loadin interfaceNaruSessionExtension
-
save
- Specified by:
savein interfaceNaruSessionExtension
-
close
public void close()- Specified by:
closein interfaceNaruSessionExtension
-