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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 64x 64x 64x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /**
* Centralized cache key definitions
* Use these functions to generate consistent cache keys
*
* All keys are versioned to handle schema changes gracefully.
* Increment CACHE_VERSION when making breaking changes to cached data structures.
*/
// Cache version - increment on breaking schema/data structure changes
export const CACHE_VERSION = 'v1';
/**
* Build a versioned cache key
*/
function buildKey(...parts: (string | number)[]): string {
return `${CACHE_VERSION}:${parts.join(':')}`;
}
export const CacheKeys = {
// Products
products: {
all: (params?: string) => buildKey('products', 'all', params || 'default'),
byId: (id: number | string) => buildKey('products', 'id', id),
bySlug: (slug: string) => buildKey('products', 'slug', slug),
byCategory: (categoryId: number | string) => buildKey('products', 'category', categoryId),
featured: () => buildKey('products', 'featured'),
trending: () => buildKey('products', 'trending'),
search: (query: string) => buildKey('products', 'search', encodeURIComponent(query)),
filters: () => buildKey('products', 'filters'),
count: (params?: string) => buildKey('products', 'count', params || 'default'),
},
// Categories
categories: {
all: () => buildKey('categories', 'all'),
byId: (id: number | string) => buildKey('categories', 'id', id),
bySlug: (slug: string) => buildKey('categories', 'slug', slug),
tree: () => buildKey('categories', 'tree'),
withProductCount: () => buildKey('categories', 'with-count'),
},
// Hero/Homepage content
content: {
hero: () => buildKey('content', 'hero'),
heroCarousel: () => buildKey('content', 'hero', 'carousel'),
heroFeatureCards: () => buildKey('content', 'hero', 'feature-cards'),
promoBanners: () => buildKey('content', 'hero', 'promo-banners'),
testimonials: () => buildKey('content', 'testimonials'),
featuredCategories: () => buildKey('content', 'featured-categories'),
},
// Support articles
support: {
articles: () => buildKey('support', 'articles'),
articleBySlug: (slug: string) => buildKey('support', 'article', slug),
categories: () => buildKey('support', 'categories'),
},
// User-specific (use with caution - shorter TTL recommended)
user: {
profile: (userId: number | string) => buildKey('user', userId, 'profile'),
orders: (userId: number | string) => buildKey('user', userId, 'orders'),
cart: (userId: number | string) => buildKey('user', userId, 'cart'),
wishlist: (userId: number | string) => buildKey('user', userId, 'wishlist'),
addresses: (userId: number | string) => buildKey('user', userId, 'addresses'),
preferences: (userId: number | string) => buildKey('user', userId, 'preferences'),
},
// Orders
orders: {
byId: (id: number | string) => buildKey('orders', 'id', id),
byUser: (userId: number | string) => buildKey('orders', 'user', userId),
recent: () => buildKey('orders', 'recent'),
},
// Admin/Analytics
admin: {
dashboardStats: () => buildKey('admin', 'dashboard', 'stats'),
recentOrders: () => buildKey('admin', 'orders', 'recent'),
lowStockProducts: () => buildKey('admin', 'products', 'low-stock'),
},
// Promotions
promotions: {
active: () => buildKey('promotions', 'active'),
byCode: (code: string) => buildKey('promotions', 'code', code),
},
// Search
search: {
suggestions: (query: string) => buildKey('search', 'suggestions', encodeURIComponent(query)),
results: (query: string, page: number) => buildKey('search', 'results', encodeURIComponent(query), page),
},
} as const;
/**
* Cache invalidation patterns
* Returns patterns or key arrays for bulk invalidation
*/
export const InvalidationPatterns = {
/** Invalidate all product caches */
allProducts: () => `${CACHE_VERSION}:products:*`,
/** Invalidate a specific product and related list caches */
product: (id: number | string) => [
CacheKeys.products.byId(id),
`${CACHE_VERSION}:products:all:*`,
CacheKeys.products.featured(),
CacheKeys.products.trending(),
CacheKeys.products.filters(),
`${CACHE_VERSION}:products:search:*`,
],
/** Invalidate category and related caches */
category: (id: number | string) => [
CacheKeys.categories.byId(id),
CacheKeys.categories.all(),
CacheKeys.categories.tree(),
CacheKeys.categories.withProductCount(),
CacheKeys.products.byCategory(id),
],
/** Invalidate all category caches */
allCategories: () => `${CACHE_VERSION}:categories:*`,
/** Invalidate user-specific caches */
user: (userId: number | string) => [
CacheKeys.user.profile(userId),
CacheKeys.user.orders(userId),
CacheKeys.user.cart(userId),
CacheKeys.user.wishlist(userId),
CacheKeys.user.addresses(userId),
CacheKeys.user.preferences(userId),
],
/** Invalidate hero/homepage content */
hero: () => [
CacheKeys.content.hero(),
CacheKeys.content.heroCarousel(),
CacheKeys.content.heroFeatureCards(),
CacheKeys.content.promoBanners(),
],
/** Invalidate all content caches */
allContent: () => `${CACHE_VERSION}:content:*`,
/** Invalidate all promotions */
allPromotions: () => `${CACHE_VERSION}:promotions:*`,
/** Invalidate all admin caches */
allAdmin: () => `${CACHE_VERSION}:admin:*`,
} as const;
/**
* Cache TTL presets in seconds
*/
export const CacheTTL = {
/** 30 seconds - for rapidly changing data */
VERY_SHORT: 30,
/** 1 minute - for frequently updated data */
SHORT: 60,
/** 5 minutes - default for most queries */
MEDIUM: 300,
/** 30 minutes - for semi-static content */
LONG: 1800,
/** 1 hour - for mostly static content */
VERY_LONG: 3600,
/** 24 hours - for static/rarely changing content */
DAY: 86400,
} as const;
/**
* Recommended TTLs for different data types
*/
export const RecommendedTTL = {
products: CacheTTL.MEDIUM,
categories: CacheTTL.LONG,
heroContent: CacheTTL.LONG,
testimonials: CacheTTL.VERY_LONG,
supportArticles: CacheTTL.LONG,
userProfile: CacheTTL.SHORT,
userCart: CacheTTL.VERY_SHORT,
promotions: CacheTTL.MEDIUM,
adminStats: CacheTTL.SHORT,
} as const;
|