Skip to content

@codesoul-co/hypha-memory / context-cache-validity

模块用法

用于读写或协调缓存状态。Context cache validity 模块公开 2 类、1 函数、4 接口。

从包入口导入

ts
import {
  InMemoryContextEnvelopeCacheStore,
  VersionValidContextCache,
  createContextCacheValidityHash,
} from '@codesoul-co/hypha-memory';

import type {
  ContextCacheVersionSnapshot,
  ContextEnvelopeCacheStore,
  VersionValidContextCacheOptions,
  VersionValidContextCacheRecord,
} from '@codesoul-co/hypha-memory';

使用要点

  • 4 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 2 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
  • 1 个函数是该模块的直接操作入口;每个 overload 的必需/可选参数与返回类型均在下方列出。

公共导出

Symbol种类签名说明
InMemoryContextEnvelopeCacheStorenew InMemoryContextEnvelopeCacheStore(): InMemoryContextEnvelopeCacheStoreIn Memory Context Envelope Cache Store 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。
VersionValidContextCachenew VersionValidContextCache(options: VersionValidContextCacheOptions): VersionValidContextCacheVersion Valid Context Cache 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。
createContextCacheValidityHash函数createContextCacheValidityHash(snapshot: ContextCacheVersionSnapshot): stringCreate Context Cache Validity Hash 函数,提供 1 个公开调用签名;参数与返回类型见下表。
ContextCacheVersionSnapshot接口interface ContextCacheVersionSnapshotContext Cache Version Snapshot 接口,共包含 9 个公开字段或方法。
ContextEnvelopeCacheStore接口interface ContextEnvelopeCacheStoreContext Envelope Cache Store 接口,共包含 4 个公开字段或方法。
VersionValidContextCacheOptions接口interface VersionValidContextCacheOptionsVersion Valid Context Cache Options 接口,共包含 5 个公开字段或方法。
VersionValidContextCacheRecord接口interface VersionValidContextCacheRecordVersion Valid Context Cache Record 接口,共包含 7 个公开字段或方法。

InMemoryContextEnvelopeCacheStore

In Memory Context Envelope Cache Store 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。

  • 种类: 类
  • 导入: import { InMemoryContextEnvelopeCacheStore } from '@codesoul-co/hypha-memory';
  • 源码模块: context-cache-validity

声明

text
export declare class InMemoryContextEnvelopeCacheStore implements ContextEnvelopeCacheStore {
    get(key: string): Promise<VersionValidContextCacheRecord | null>;
    set(key: string, value: VersionValidContextCacheRecord): Promise<void>;
    delete(key: string): Promise<void>;
    invalidateScope(scopeHash: string): Promise<number>;
}

公开成员

成员种类签名说明
constructor构造函数(): InMemoryContextEnvelopeCacheStore创建该类的实例。
delete方法delete(key: string): Promise<void>公开方法;参数与返回类型以签名列为准。
get方法get(key: string): Promise<VersionValidContextCacheRecord | null>公开方法;参数与返回类型以签名列为准。
invalidateScope方法invalidateScope(scopeHash: string): Promise<number>公开方法;参数与返回类型以签名列为准。
set方法set(key: string, value: VersionValidContextCacheRecord): Promise<void>公开方法;参数与返回类型以签名列为准。

VersionValidContextCache

Version Valid Context Cache 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。

  • 种类: 类
  • 导入: import { VersionValidContextCache } from '@codesoul-co/hypha-memory';
  • 源码模块: context-cache-validity

声明

text
export declare class VersionValidContextCache implements MemoryProjectionInvalidationTarget {
    readonly id: string;
    constructor(options: VersionValidContextCacheOptions);
    invalidateScope(scopeHash: string): Promise<number>;
    get(key: string, current: ContextCacheVersionSnapshot): Promise<ContextEnvelope | null>;
    set(key: string, envelope: ContextEnvelope, snapshot: ContextCacheVersionSnapshot, expiresAt?: string): Promise<void>;
}

公开成员

成员种类签名说明
constructor构造函数(options: VersionValidContextCacheOptions): VersionValidContextCache创建该类的实例。
get方法get(key: string, current: ContextCacheVersionSnapshot): Promise<ContextEnvelope | null>公开方法;参数与返回类型以签名列为准。
id属性readonly id: string公开属性;类型、只读和可选状态以签名列为准。
invalidateScope方法invalidateScope(scopeHash: string): Promise<number>公开方法;参数与返回类型以签名列为准。
set方法set(key: string, envelope: ContextEnvelope, snapshot: ContextCacheVersionSnapshot, expiresAt?: string): Promise<void>公开方法;参数与返回类型以签名列为准。

createContextCacheValidityHash

Create Context Cache Validity Hash 函数,提供 1 个公开调用签名;参数与返回类型见下表。

  • 种类: 函数
  • 导入: import { createContextCacheValidityHash } from '@codesoul-co/hypha-memory';
  • 源码模块: context-cache-validity

声明

text
export declare function createContextCacheValidityHash(snapshot: ContextCacheVersionSnapshot): string;

调用签名

text
createContextCacheValidityHash(snapshot: ContextCacheVersionSnapshot): string

参数

参数类型必需说明
snapshotContextCacheVersionSnapshot必需参数;接受的值由类型列定义。

返回值

  • 类型: string
  • 说明: 返回值契约由上述类型定义。

ContextCacheVersionSnapshot

Context Cache Version Snapshot 接口,共包含 9 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ContextCacheVersionSnapshot } from '@codesoul-co/hypha-memory';
  • 源码模块: context-cache-validity

声明

text
export interface ContextCacheVersionSnapshot {
    contextProfileRevision: string;
    memoryProfileRevision: string;
    scopeHash: string;
    providerRevision?: string;
    policyRevision?: string;
    mutationGeneration: string;
    selectedMemoryVersionIds: string[];
    sourceHashes: Record<string, string>;
    artifactHashes?: Record<string, string>;
}

契约成员

成员种类签名说明
artifactHashes属性artifactHashes?: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。
contextProfileRevision属性contextProfileRevision: string公开属性;类型、只读和可选状态以签名列为准。
memoryProfileRevision属性memoryProfileRevision: string公开属性;类型、只读和可选状态以签名列为准。
mutationGeneration属性mutationGeneration: string公开属性;类型、只读和可选状态以签名列为准。
policyRevision属性policyRevision?: string公开属性;类型、只读和可选状态以签名列为准。
providerRevision属性providerRevision?: string公开属性;类型、只读和可选状态以签名列为准。
scopeHash属性scopeHash: string公开属性;类型、只读和可选状态以签名列为准。
selectedMemoryVersionIds属性selectedMemoryVersionIds: string[]公开属性;类型、只读和可选状态以签名列为准。
sourceHashes属性sourceHashes: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。

ContextEnvelopeCacheStore

Context Envelope Cache Store 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ContextEnvelopeCacheStore } from '@codesoul-co/hypha-memory';
  • 源码模块: context-cache-validity

声明

text
export interface ContextEnvelopeCacheStore {
    get(key: string): Promise<VersionValidContextCacheRecord | null>;
    set(key: string, value: VersionValidContextCacheRecord): Promise<void>;
    delete(key: string): Promise<void>;
    invalidateScope(scopeHash: string): Promise<number>;
}

契约成员

成员种类签名说明
delete方法delete(key: string): Promise<void>公开方法;参数与返回类型以签名列为准。
get方法get(key: string): Promise<VersionValidContextCacheRecord | null>公开方法;参数与返回类型以签名列为准。
invalidateScope方法invalidateScope(scopeHash: string): Promise<number>公开方法;参数与返回类型以签名列为准。
set方法set(key: string, value: VersionValidContextCacheRecord): Promise<void>公开方法;参数与返回类型以签名列为准。

VersionValidContextCacheOptions

Version Valid Context Cache Options 接口,共包含 5 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { VersionValidContextCacheOptions } from '@codesoul-co/hypha-memory';
  • 源码模块: context-cache-validity

声明

text
export interface VersionValidContextCacheOptions {
    store: ContextEnvelopeCacheStore;
    now?: () => string;
    artifactStore?: ContextArtifactStore;
    projectionId?: string;
    generations?: MemoryMutationGenerationStore;
}

契约成员

成员种类签名说明
artifactStore属性artifactStore?: ContextArtifactStore公开属性;类型、只读和可选状态以签名列为准。
generations属性generations?: MemoryMutationGenerationStore公开属性;类型、只读和可选状态以签名列为准。
now方法now?(): string公开方法;参数与返回类型以签名列为准。
projectionId属性projectionId?: string公开属性;类型、只读和可选状态以签名列为准。
store属性store: ContextEnvelopeCacheStore公开属性;类型、只读和可选状态以签名列为准。

VersionValidContextCacheRecord

Version Valid Context Cache Record 接口,共包含 7 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { VersionValidContextCacheRecord } from '@codesoul-co/hypha-memory';
  • 源码模块: context-cache-validity

声明

text
export interface VersionValidContextCacheRecord {
    key: string;
    envelope: ContextEnvelope;
    snapshot: ContextCacheVersionSnapshot;
    validityHash: string;
    envelopeHash: string;
    createdAt: string;
    expiresAt?: string;
}

契约成员

成员种类签名说明
createdAt属性createdAt: string公开属性;类型、只读和可选状态以签名列为准。
envelope属性envelope: ContextEnvelope公开属性;类型、只读和可选状态以签名列为准。
envelopeHash属性envelopeHash: string公开属性;类型、只读和可选状态以签名列为准。
expiresAt属性expiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
key属性key: string公开属性;类型、只读和可选状态以签名列为准。
snapshot属性snapshot: ContextCacheVersionSnapshot公开属性;类型、只读和可选状态以签名列为准。
validityHash属性validityHash: string公开属性;类型、只读和可选状态以签名列为准。