Skip to content

@codesoul-co/hypha-inference / cache

Using this module

Use the Cache module for reading, writing, or coordinating cache state. It exports 2 classes, 4 functions, 3 interfaces, 1 type.

Import from the package entrypoint

ts
import {
  InferenceCacheManager,
  InferenceCacheOperationTimeoutError,
  hashContent,
  inferenceCacheScopeHash,
  isKvCacheExpired,
  runInferenceCacheOperation,
} from '@codesoul-co/hypha-inference';

import type {
  InferenceCacheManagerOptions,
  KvCacheCreateInput,
  PrefixCacheCreateInput,
  InferenceCacheOperation,
} from '@codesoul-co/hypha-inference';

Usage patterns

  • Use the 4 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.
  • The module exposes 2 classes as constructable runtime implementations. Each symbol entry lists its constructor and public methods.
  • The module exposes 4 functions as direct operation entrypoints. Every overload, required/optional parameter, and return type is documented below.

Public exports

SymbolKindSignatureDescription
InferenceCacheManagerclassnew InferenceCacheManager(options: InferenceCacheManagerOptions): InferenceCacheManagerInference Cache Manager class with 5 public constructor or member entries; its exact declarations are listed below.
InferenceCacheOperationTimeoutErrorclassnew InferenceCacheOperationTimeoutError(operation: InferenceCacheOperation, timeoutMs: number): InferenceCacheOperationTimeoutErrorInference Cache Operation Timeout Error class with 11 public constructor or member entries; its exact declarations are listed below.
hashContentfunctionhashContent(content: string): stringHash Content function with 1 public call signature; parameters and return types are listed below.
inferenceCacheScopeHashfunctioninferenceCacheScopeHash(scope: InferenceCacheScope | undefined): stringInference Cache Scope Hash function with 1 public call signature; parameters and return types are listed below.
isKvCacheExpiredfunctionisKvCacheExpired(ref: KvCacheRef, now?: Date): booleanIs Kv Cache Expired function with 1 public call signature; parameters and return types are listed below.
runInferenceCacheOperationfunctionrunInferenceCacheOperation<T>(operation: InferenceCacheOperation, task: () => Promise<T>, timeoutMs: number): Promise<T>Run Inference Cache Operation function with 1 public call signature; parameters and return types are listed below.
InferenceCacheManagerOptionsinterfaceinterface InferenceCacheManagerOptionsInference Cache Manager Options interface with 4 public fields or methods.
KvCacheCreateInputinterfaceinterface KvCacheCreateInputKv Cache Create Input interface with 7 public fields or methods.
PrefixCacheCreateInputinterfaceinterface PrefixCacheCreateInputPrefix Cache Create Input interface with 6 public fields or methods.
InferenceCacheOperationtypetype InferenceCacheOperation = 'prefix_read' | 'prefix_write' | 'kv_read' | 'kv_write' | 'invalidate'Public type alias for Inference Cache Operation; the declaration contains its complete type expression.

InferenceCacheManager

Inference Cache Manager class with 5 public constructor or member entries; its exact declarations are listed below.

  • Kind: class
  • Import: import { InferenceCacheManager } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export declare class InferenceCacheManager {
    constructor(options: InferenceCacheManagerOptions);
    putPrefix(input: PrefixCacheCreateInput): Promise<PrefixCacheRef>;
    getPrefix(ref: PrefixCacheRef): Promise<string | null>;
    putKv(input: KvCacheCreateInput, value: unknown): Promise<KvCacheRef>;
    getKv(ref: KvCacheRef): Promise<unknown | null>;
}

Public members

MemberKindSignatureDescription
constructorconstructor(options: InferenceCacheManagerOptions): InferenceCacheManagerCreates an instance of this class.
getKvmethodgetKv(ref: KvCacheRef): Promise<unknown | null>Public method; parameters and return type are shown in the signature.
getPrefixmethodgetPrefix(ref: PrefixCacheRef): Promise<string | null>Public method; parameters and return type are shown in the signature.
putKvmethodputKv(input: KvCacheCreateInput, value: unknown): Promise<KvCacheRef>Public method; parameters and return type are shown in the signature.
putPrefixmethodputPrefix(input: PrefixCacheCreateInput): Promise<PrefixCacheRef>Public method; parameters and return type are shown in the signature.

InferenceCacheOperationTimeoutError

Inference Cache Operation Timeout Error class with 11 public constructor or member entries; its exact declarations are listed below.

  • Kind: class
  • Import: import { InferenceCacheOperationTimeoutError } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export declare class InferenceCacheOperationTimeoutError extends Error {
    readonly operation: InferenceCacheOperation;
    readonly timeoutMs: number;
    readonly code = "INFERENCE_CACHE_OPERATION_TIMEOUT";
    constructor(operation: InferenceCacheOperation, timeoutMs: number);
}

Public members

MemberKindSignatureDescription
causepropertycause?: unknownPublic property; its type, readonly modifier and optionality are shown in the signature.
codepropertyreadonly code: "INFERENCE_CACHE_OPERATION_TIMEOUT"Public property; its type, readonly modifier and optionality are shown in the signature.
constructorconstructor(operation: InferenceCacheOperation, timeoutMs: number): InferenceCacheOperationTimeoutErrorCreates an instance of this class.
messagepropertymessage: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
namepropertyname: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
operationpropertyreadonly operation: InferenceCacheOperationPublic property; its type, readonly modifier and optionality are shown in the signature.
stackpropertystack?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
static captureStackTracemethodstatic captureStackTrace(targetObject: object, constructorOpt?: Function): voidCreates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called. js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}. The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace. The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance: js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a();
static prepareStackTracemethodstatic prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): anyPublic method; parameters and return type are shown in the signature.
static stackTraceLimitpropertystatic stackTraceLimit: numberThe Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
timeoutMspropertyreadonly timeoutMs: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

hashContent

Hash Content function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { hashContent } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export declare function hashContent(content: string): string;

Call signature

text
hashContent(content: string): string

Parameters

ParameterTypeRequiredDescription
contentstringYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: string
  • Description: The return contract is defined by the type shown above.

inferenceCacheScopeHash

Inference Cache Scope Hash function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { inferenceCacheScopeHash } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export declare function inferenceCacheScopeHash(scope: InferenceCacheScope | undefined): string;

Call signature

text
inferenceCacheScopeHash(scope: InferenceCacheScope | undefined): string

Parameters

ParameterTypeRequiredDescription
scopeInferenceCacheScopeYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: string
  • Description: The return contract is defined by the type shown above.

isKvCacheExpired

Is Kv Cache Expired function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { isKvCacheExpired } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export declare function isKvCacheExpired(ref: KvCacheRef, now?: Date): boolean;

Call signature

text
isKvCacheExpired(ref: KvCacheRef, now?: Date): boolean

Parameters

ParameterTypeRequiredDescription
refKvCacheRefYesRequired parameter; accepted values are defined by the type column.
nowDateNoOptional parameter; accepted values are defined by the type column.

Returns

  • Type: boolean
  • Description: The return contract is defined by the type shown above.

runInferenceCacheOperation

Run Inference Cache Operation function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { runInferenceCacheOperation } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export declare function runInferenceCacheOperation<T>(operation: InferenceCacheOperation, task: () => Promise<T>, timeoutMs: number): Promise<T>;

Call signature

text
runInferenceCacheOperation<T>(operation: InferenceCacheOperation, task: () => Promise<T>, timeoutMs: number): Promise<T>

Parameters

ParameterTypeRequiredDescription
operationInferenceCacheOperationYesRequired parameter; accepted values are defined by the type column.
task() => Promise<T>YesRequired parameter; accepted values are defined by the type column.
timeoutMsnumberYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: Promise<T>
  • Description: The return contract is defined by the type shown above.

InferenceCacheManagerOptions

Inference Cache Manager Options interface with 4 public fields or methods.

  • Kind: interface
  • Import: import type { InferenceCacheManagerOptions } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export interface InferenceCacheManagerOptions {
    prefixCache: PrefixCacheProvider;
    kvCache: KvCacheProvider;
    now?: () => Date;
    operationTimeoutMs?: number;
}

Contract members

MemberKindSignatureDescription
kvCachepropertykvCache: KvCacheProviderPublic property; its type, readonly modifier and optionality are shown in the signature.
nowmethodnow?(): DatePublic method; parameters and return type are shown in the signature.
operationTimeoutMspropertyoperationTimeoutMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
prefixCachepropertyprefixCache: PrefixCacheProviderPublic property; its type, readonly modifier and optionality are shown in the signature.

KvCacheCreateInput

Kv Cache Create Input interface with 7 public fields or methods.

  • Kind: interface
  • Import: import type { KvCacheCreateInput } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export interface KvCacheCreateInput {
    id: string;
    provider: string;
    modelAlias: string;
    scope: KvCacheScope;
    cacheScope?: InferenceCacheScope;
    ttlMs?: number;
    metadata?: Record<string, unknown>;
}

Contract members

MemberKindSignatureDescription
cacheScopepropertycacheScope?: InferenceCacheScopePublic property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
modelAliaspropertymodelAlias: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
providerpropertyprovider: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
scopepropertyscope: KvCacheScopePublic property; its type, readonly modifier and optionality are shown in the signature.
ttlMspropertyttlMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

PrefixCacheCreateInput

Prefix Cache Create Input interface with 6 public fields or methods.

  • Kind: interface
  • Import: import type { PrefixCacheCreateInput } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export interface PrefixCacheCreateInput {
    id: string;
    version: string;
    content: string;
    tokenCount?: number;
    cacheScope?: InferenceCacheScope;
    metadata?: Record<string, unknown>;
}

Contract members

MemberKindSignatureDescription
cacheScopepropertycacheScope?: InferenceCacheScopePublic property; its type, readonly modifier and optionality are shown in the signature.
contentpropertycontent: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
tokenCountpropertytokenCount?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
versionpropertyversion: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

InferenceCacheOperation

Public type alias for Inference Cache Operation; the declaration contains its complete type expression.

  • Kind: type
  • Import: import type { InferenceCacheOperation } from '@codesoul-co/hypha-inference';
  • Source module: cache

Declaration

text
export type InferenceCacheOperation = 'prefix_read' | 'prefix_write' | 'kv_read' | 'kv_write' | 'invalidate';