/** * Cache Management Utilities * Direct pass-through to fetchff's cache management system * Maintains vendor abstraction while providing full cache control * * @module cache */ import { mutate as fetchffMutate, getCache as fetchffGetCache, setCache as fetchffSetCache, deleteCache as fetchffDeleteCache, revalidate as fetchffRevalidate, revalidateAll as fetchffRevalidateAll, subscribe as fetchffSubscribe } from 'fetchff'; export * from './strategies'; export * from './patterns'; /** * Update cached data for a specific key * Supports optimistic updates and background revalidation * * @param cacheKey - The cache key or URL pattern * @param data - New data to set in cache * @param revalidate - Whether to revalidate after mutation * * @example * ```typescript * // Update specific cache entry * await mutate('/api/users/123', updatedUser); * * // Update with revalidation * await mutate('/api/users/123', updatedUser, true); * * // Update multiple entries with pattern * await mutate('/api/users/*', null, true); // Invalidate all users * ``` */ export declare const mutate: typeof fetchffMutate; /** * Get cached data for a specific key * Returns null if not in cache or expired * * @param cacheKey - The cache key or URL * @returns Cached data or null * * @example * ```typescript * const cachedUser = getCache('/api/users/123'); * if (cachedUser) { * console.log('Using cached data:', cachedUser); * } * ``` */ export declare const getCache: typeof fetchffGetCache; /** * Set cache data directly * Useful for pre-populating cache or manual cache management * * @param cacheKey - The cache key or URL * @param data - Data to cache * @param options - Cache options (ttl, etc.) * * @example * ```typescript * // Pre-populate cache * setCache('/api/users/123', userData, { ttl: 300 }); * * // Cache with custom expiry * setCache('/api/config', config, { ttl: 3600 }); * ``` */ export declare const setCache: typeof fetchffSetCache; /** * Delete cached data for a specific key or pattern * Supports wildcard patterns for bulk deletion * * @param cacheKey - The cache key, URL, or pattern * * @example * ```typescript * // Delete specific entry * deleteCache('/api/users/123'); * * // Delete all user cache entries * deleteCache('/api/users/*'); * * // Clear all cache * deleteCache('*'); * ``` */ export declare const deleteCache: typeof fetchffDeleteCache; /** * Revalidate cached data by fetching fresh data * Triggers background fetch to update cache * * @param cacheKey - The cache key or URL to revalidate * @returns Promise that resolves when revalidation completes * * @example * ```typescript * // Revalidate specific endpoint * await revalidate('/api/users/123'); * * // Revalidate pattern * await revalidate('/api/users/*'); * ``` */ export declare const revalidate: typeof fetchffRevalidate; /** * Revalidate all cached data * Useful for global refresh or after authentication changes * * @returns Promise that resolves when all revalidations complete * * @example * ```typescript * // After login, refresh all cached data * await revalidateAll(); * ``` */ export declare const revalidateAll: typeof fetchffRevalidateAll; /** * Subscribe to cache updates for real-time synchronization * Useful for keeping UI in sync across components/tabs * * @param cacheKey - The cache key or pattern to watch * @param callback - Function called when cache updates * @returns Unsubscribe function * * @example * ```typescript * // Subscribe to user updates * const unsubscribe = subscribe('/api/users/123', (data) => { * console.log('User data updated:', data); * updateUI(data); * }); * * // Later: cleanup * unsubscribe(); * ``` */ export declare const subscribe: typeof fetchffSubscribe; /** * Cache utilities grouped for convenient access * * @example * ```typescript * import { cache } from '@plyaz/api'; * * // Use utilities * cache.mutate('/api/data', newData); * cache.deleteCache('/api/old/*'); * cache.revalidateAll(); * ``` */ export declare const cache: { readonly mutate: typeof fetchffMutate; readonly getCache: typeof fetchffGetCache; readonly setCache: typeof fetchffSetCache; readonly deleteCache: typeof fetchffDeleteCache; readonly revalidate: typeof fetchffRevalidate; readonly revalidateAll: typeof fetchffRevalidateAll; readonly subscribe: typeof fetchffSubscribe; }; /** * Helper function to clear cache by pattern * Convenience wrapper around deleteCache * * @example * ```typescript * // Clear all user-related cache * clearCachePattern('/api/users'); * * // Clear everything * clearCachePattern('*'); * ``` */ export declare function clearCachePattern(pattern: string): void; /** * Helper function to invalidate and refetch * Combines deletion and revalidation * * @example * ```typescript * // Force fresh fetch * await invalidateAndRefetch('/api/users/123'); * ``` */ export declare function invalidateAndRefetch(cacheKey: string): Promise; //# sourceMappingURL=index.d.ts.map