All files / src/lib/cache index.ts

0% Statements 0/102
100% Branches 0/0
0% Functions 0/1
0% Lines 0/102

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103                                                                                                                                                                                                             
/**
 * Cache Module
 *
 * Provides in-memory caching for database queries and computed values.
 *
 * Usage:
 * ```typescript
 * import { getCachedProducts, invalidateProductCache } from '@/lib/cache';
 *
 * // In API routes - use cached queries
 * const products = await getCachedProducts({ categoryId: 1 });
 *
 * // After mutations - invalidate cache
 * await prisma.product.update({ ... });
 * invalidateProductCache(productId);
 *
 * // Use SWR pattern for high-traffic endpoints
 * import { getWithSWR, SWRPresets } from '@/lib/cache';
 * const data = await getWithSWR('my-key', {
 *   ...SWRPresets.moderate,
 *   fetcher: () => fetchData(),
 * });
 * ```
 */

// Core cache service
export { cacheService, CacheService } from './cache-service';
export type { CacheOptions, CacheStats } from './cache-service';

// Cache keys, TTL constants, and invalidation patterns
export {
  CacheKeys,
  CacheTTL,
  RecommendedTTL,
  InvalidationPatterns,
  CACHE_VERSION,
} from './cache-keys';

// Stale-While-Revalidate cache
export {
  getWithSWR,
  swrFetch,
  swrFetchWithTimes,
  invalidateSWR,
  prefetchSWR,
  SWRPresets,
} from './swr-cache';

// Cached query functions
export {
  // Products
  getCachedProducts,
  getCachedProductById,
  getCachedProductsByCategory,
  getCachedProductFilters,
  // Categories
  getCachedCategories,
  getCachedCategoriesWithCount,
  getCachedCategoryById,
  getCachedCategoryBySlug,
  // Hero/Content
  getCachedHeroData,
  getCachedTestimonials,
  // Support
  getCachedSupportArticles,
  getCachedSupportArticleBySlug,
  // Promotions
  getCachedActivePromotions,
} from './cached-queries';

// Cache invalidation service and functions
export {
  // New invalidation service
  invalidationService,
  // Products
  invalidateAllProductCaches,
  invalidateProductCache,
  invalidateProductListCaches,
  // Categories
  invalidateAllCategoryCaches,
  invalidateCategoryCache,
  onCategoryUpdate,
  // Content
  invalidateAllContentCaches,
  invalidateHeroCache,
  invalidateTestimonialsCache,
  // Support
  invalidateAllSupportCaches,
  invalidateSupportArticleCache,
  // User
  invalidateUserCaches,
  invalidateUserCache,
  // Promotions
  invalidateAllPromotionCaches,
  invalidatePromoCodeCache,
  // Admin
  invalidateAdminCaches,
  // Global
  flushAllCaches,
  getCacheStats,
  getCachedKeys,
} from './cache-invalidation';