@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 | 种类 | 签名 | 说明 |
|---|---|---|---|
InMemoryContextEnvelopeCacheStore | 类 | new InMemoryContextEnvelopeCacheStore(): InMemoryContextEnvelopeCacheStore | In Memory Context Envelope Cache Store 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。 |
VersionValidContextCache | 类 | new VersionValidContextCache(options: VersionValidContextCacheOptions): VersionValidContextCache | Version Valid Context Cache 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。 |
createContextCacheValidityHash | 函数 | createContextCacheValidityHash(snapshot: ContextCacheVersionSnapshot): string | Create Context Cache Validity Hash 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
ContextCacheVersionSnapshot | 接口 | interface ContextCacheVersionSnapshot | Context Cache Version Snapshot 接口,共包含 9 个公开字段或方法。 |
ContextEnvelopeCacheStore | 接口 | interface ContextEnvelopeCacheStore | Context Envelope Cache Store 接口,共包含 4 个公开字段或方法。 |
VersionValidContextCacheOptions | 接口 | interface VersionValidContextCacheOptions | Version Valid Context Cache Options 接口,共包含 5 个公开字段或方法。 |
VersionValidContextCacheRecord | 接口 | interface VersionValidContextCacheRecord | Version 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参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
snapshot | ContextCacheVersionSnapshot | 是 | 必需参数;接受的值由类型列定义。 |
返回值
- 类型:
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 | 公开属性;类型、只读和可选状态以签名列为准。 |
