UNPKG

@spoolcms/nextjs

Version:

The beautiful headless CMS for Next.js developers

40 lines (39 loc) 1.2 kB
/** * Request deduplication and caching utilities for Spool CMS * Provides different caching strategies for server and client contexts */ export interface CacheEntry<T> { data: T; timestamp: number; promise?: Promise<T>; } export interface CacheOptions { ttl?: number; maxSize?: number; } /** * Generate a cache key for a request */ export declare function generateCacheKey(baseUrl: string, siteId: string, collection: string, slug?: string, options?: any): string; /** * Unified caching interface that works in both server and client contexts */ export declare class UnifiedCache<T> { private environment; get(key: string): Promise<T | null>; set(key: string, data: T): Promise<void>; getOrFetch<T>(key: string, fetcher: () => Promise<T>): Promise<T>; clear(): void; } /** * Create a cached fetch function that works in both server and client contexts */ export declare function createCachedFetch(): (url: string, options: RequestInit) => Promise<Response>; /** * Global cache instance */ export declare const globalCache: UnifiedCache<unknown>; /** * Clear all caches (useful for testing) */ export declare function clearAllCaches(): void;