UNPKG

@mdfriday/foundry

Version:

The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.

91 lines 2.11 kB
/** * 并发安全的缓存实现,专为站点构建场景优化 * 支持多个页面并发访问时避免重复创建相同对象 */ export declare class ConcurrentCache<K, V> { private cache; private pendingPromises; private deletedKeys; constructor(); /** * Get value from cache */ get(key: K): V | undefined; /** * Set value in cache */ set(key: K, value: V): void; /** * Check if key exists in cache */ has(key: K): boolean; /** * Check if key is currently being created */ isPending(key: K): boolean; /** * Remove key from cache */ delete(key: K): boolean; /** * Clear all cache entries and pending promises */ clear(): void; /** * Get cache size */ size(): number; /** * Get pending promises count */ pendingCount(): number; /** * 并发安全的获取或创建值 * 如果多个并发请求访问同一个key,只会创建一次 */ getOrCreate(key: K, create: (key: K) => Promise<V>): Promise<V>; /** * 创建并缓存值 */ private createAndCache; /** * 执行创建函数,包装错误处理 */ private executeCreate; /** * 获取缓存统计信息 */ getStats(): CacheStats; /** * 批量预加载数据 */ preload(entries: Array<{ key: K; create: (key: K) => Promise<V>; }>): Promise<void>; } /** * 缓存统计信息 */ export interface CacheStats { size: number; pendingCount: number; keys: unknown[]; pendingKeys: unknown[]; } /** * DynaCache interface implementation */ export interface DynaCache<K, V> { getOrCreate(key: K, create: (key: K) => Promise<V>): Promise<V>; getStats?(): CacheStats; } /** * 创建一个新的并发缓存实例 */ export declare function createCache<K, V>(): ConcurrentCache<K, V>; /** * 全局缓存实例,用于站点构建时的数据共享 */ export declare const globalBuildCache: ConcurrentCache<string, any>; //# sourceMappingURL=cache.d.ts.map