UNPKG

@toolkit-p2p/mesh-cache

Version:

Content-addressed mesh cache for toolkit-p2p

99 lines 2.3 kB
/** * Mesh cache - content-addressed distributed cache */ import type { Block, CID, CacheStats } from './types.js'; import type { Transport } from '@toolkit-p2p/transport'; export interface MeshCacheOpts { /** Transport layer for block exchange */ transport: Transport; /** Maximum cache size in bytes (0 = unlimited) */ maxSize?: number; /** Default TTL for blocks in seconds (0 = no expiration) */ defaultTTL?: number; /** Garbage collection interval in ms */ gcInterval?: number; } export declare class MeshCache { private storage; private transport; private opts; private gcTimer; private pendingRequests; constructor(opts: MeshCacheOpts); /** * Initialize cache */ init(): Promise<void>; /** * Add data to cache */ put(data: Uint8Array, opts?: { pinned?: boolean; ttl?: number; }): Promise<CID>; /** * Get data from cache (or request from mesh) */ get(cid: CID, timeout?: number): Promise<Block | null>; /** * Check if block exists locally */ has(cid: CID): Promise<boolean>; /** * Delete block from cache */ delete(cid: CID): Promise<void>; /** * Pin a block (prevent garbage collection) */ pin(cid: CID): Promise<void>; /** * Unpin a block (allow garbage collection) */ unpin(cid: CID): Promise<void>; /** * Get cache statistics */ getStats(): Promise<CacheStats>; /** * List all CIDs in cache */ list(): Promise<CID[]>; /** * Clear all blocks */ clear(): Promise<void>; /** * Close cache and cleanup */ close(): Promise<void>; /** * Setup transport message handlers */ private setupTransport; /** * Handle incoming cache messages */ private handleMessage; /** * Handle block request from peer */ private handleBlockRequest; /** * Handle block response from peer */ private handleBlockResponse; /** * Request block from mesh */ private requestFromMesh; /** * Announce block to mesh */ private announce; /** * Run garbage collection */ private runGC; } //# sourceMappingURL=cache.d.ts.map