Class NaruCacheBaseline

java.lang.Object
net.thevpc.naru.ext.models.cache.NaruCacheBaseline

public class NaruCacheBaseline extends Object
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 Details

    • SCHEMA_VERSION

      public static final int SCHEMA_VERSION
      Bumped if the on-disk shape changes in a way older readers cannot handle.
      See Also:
  • Constructor Details

  • Method Details

    • empty

      public static NaruCacheBaseline empty()
    • getProviderName

      public String getProviderName()
    • getModelName

      public String getModelName()
    • getCachingMode

      public NaruCachingMode getCachingMode()
    • getSegmentKeys

      public List<String> getSegmentKeys()
    • getCachedResourceId

      public String getCachedResourceId()
    • getResourceExpiresAt

      public long getResourceExpiresAt()
    • getUpdatedAt

      public long getUpdatedAt()
    • matches

      public boolean matches(String providerName, String modelName, NaruCachingMode mode)
      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 at now.

      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

      public NaruCacheBaseline withSegmentKeys(List<String> keys)
    • withResource

      public NaruCacheBaseline withResource(String resourceId, long expiresAt, long now)
    • withUpdatedAt

      public NaruCacheBaseline withUpdatedAt(long now)
    • toElement

      public net.thevpc.nuts.elem.NElement toElement()
    • fromElement

      public static NaruCacheBaseline fromElement(net.thevpc.nuts.elem.NElement e)
      Reads a baseline back. Any structural surprise yields empty() rather than an exception: a corrupt cache hint must never cost the user their session, and a cold cache is always a safe answer.