Class NaruModelCacheExtension

java.lang.Object
net.thevpc.naru.ext.models.cache.NaruModelCacheExtension
All Implemented Interfaces:
NaruSessionExtension, net.thevpc.nuts.spi.NComponent

public class NaruModelCacheExtension extends Object implements NaruSessionExtension
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 Details

  • Constructor Details

    • NaruModelCacheExtension

      public NaruModelCacheExtension()
  • Method Details

    • of

      public static NaruModelCacheExtension of(NaruSession session)
      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

      public NaruCacheBaseline baseline(String providerName, String modelName, NaruCachingMode mode)
    • 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

      public void clearResource(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.
    • clear

      public void clear()
    • name

      public String name()
      Specified by:
      name in interface NaruSessionExtension
    • load

      public net.thevpc.nuts.util.NOptional<net.thevpc.nuts.elem.NElement> load(NaruSession session, net.thevpc.nuts.io.NPath file)
      Specified by:
      load in interface NaruSessionExtension
    • save

      public net.thevpc.nuts.elem.NElement save(NaruSession session)
      Specified by:
      save in interface NaruSessionExtension
    • close

      public void close()
      Specified by:
      close in interface NaruSessionExtension