Problem Statement
How do you design cache invalidation for product pages updated by merchants within seconds?
Explanation
Prefer precise invalidation over global flushes. Keep a mapping from product IDs to cache keys and issue targeted purge or key bump on update. Pair this with short TTLs and stale-while-revalidate so the CDN can serve slightly stale content while refreshing in the background.
For dynamic fragments, use Edge Side Includes or micro-APIs with independent TTLs. On write, publish an event that triggers cache purge in edge and application caches for that product ID.
Code Solution
SolutionRead Only
onProductUpdate(id){ purge(`product:*:${id}:*`); emit('product.updated', id); }