[{"data":1,"prerenderedAt":188},["ShallowReactive",2],{"term-c\u002Fcache-invalidation":3,"related-c\u002Fcache-invalidation":177},{"id":4,"title":5,"acronym":6,"body":7,"category":159,"description":160,"difficulty":161,"extension":162,"letter":163,"meta":164,"navigation":165,"path":166,"related":167,"seo":171,"sitemap":172,"stem":175,"subcategory":6,"__hash__":176},"terms\u002Fterms\u002Fc\u002Fcache-invalidation.md","Cache Invalidation",null,{"type":8,"value":9,"toc":153},"minimark",[10,15,19,23,26,30,142,146,149],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 - The Vibe Check",[16,17,18],"p",{},"There's an old joke that there are only two hard problems in computer science: cache invalidation, naming things, and off-by-one errors. Caching makes things fast by keeping a copy of data around, but the moment the real data changes, that copy becomes a lie. Cache invalidation is the never-ending job of deciding when to throw that stale copy away before it fools someone.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"Cache invalidation is the process of removing or updating cached data once the underlying source data changes, to prevent clients from reading stale values. Common strategies include time-based expiration (TTL), explicit invalidation on write, and event-driven invalidation triggered by change notifications, each trading off staleness risk against cache hit rate.",[11,27,29],{"id":28},"show-me-the-code","Show Me The Code",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-javascript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F Invalidate on write instead of waiting for the TTL\nawait db.user.update({ where: { id }, data });\nawait redis.del(`user:${id}`);\n","javascript","",[38,39,40,49,107],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,48],{"class":47},"sHwdD","\u002F\u002F Invalidate on write instead of waiting for the TTL\n",[41,50,52,56,60,64,67,69,73,76,79,83,86,89,92,95,98,101,104],{"class":43,"line":51},2,[41,53,55],{"class":54},"s7zQu","await",[41,57,59],{"class":58},"sTEyZ"," db",[41,61,63],{"class":62},"sMK4o",".",[41,65,66],{"class":58},"user",[41,68,63],{"class":62},[41,70,72],{"class":71},"s2Zo4","update",[41,74,75],{"class":58},"(",[41,77,78],{"class":62},"{",[41,80,82],{"class":81},"swJcz"," where",[41,84,85],{"class":62},":",[41,87,88],{"class":62}," {",[41,90,91],{"class":58}," id ",[41,93,94],{"class":62},"},",[41,96,97],{"class":58}," data ",[41,99,100],{"class":62},"}",[41,102,103],{"class":58},")",[41,105,106],{"class":62},";\n",[41,108,110,112,115,117,120,122,125,129,132,135,138,140],{"class":43,"line":109},3,[41,111,55],{"class":54},[41,113,114],{"class":58}," redis",[41,116,63],{"class":62},[41,118,119],{"class":71},"del",[41,121,75],{"class":58},[41,123,124],{"class":62},"`",[41,126,128],{"class":127},"sfazB","user:",[41,130,131],{"class":62},"${",[41,133,134],{"class":58},"id",[41,136,137],{"class":62},"}`",[41,139,103],{"class":58},[41,141,106],{"class":62},[11,143,145],{"id":144},"when-youll-hear-this","When You'll Hear This",[16,147,148],{},"\"We ship a bug, users see stale data, and it's always cache invalidation.\" \u002F \"Set a short TTL instead of trying to invalidate perfectly on every write.\"",[150,151,152],"style",{},"html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":36,"searchDepth":51,"depth":51,"links":154},[155,156,157,158],{"id":13,"depth":51,"text":14},{"id":21,"depth":51,"text":22},{"id":28,"depth":51,"text":29},{"id":144,"depth":51,"text":145},"backend","There's an old joke that there are only two hard problems in computer science: cache invalidation, naming things, and off-by-one errors.","intermediate","md","c",{},true,"\u002Fterms\u002Fc\u002Fcache-invalidation",[168,169,170],"Caching","Redis","Change Data Capture",{"title":5,"description":160},{"changefreq":173,"priority":174},"weekly",0.7,"terms\u002Fc\u002Fcache-invalidation","hYVz8YONS1AAoMfiQN4TEbcQZB0yy9gZkWFxeKrjYOA",[178,181,185],{"title":168,"path":179,"acronym":6,"category":159,"difficulty":161,"description":180},"\u002Fterms\u002Fc\u002Fcaching","Caching is saving the result of a slow operation so you can reuse it quickly next time.",{"title":170,"path":182,"acronym":6,"category":159,"difficulty":183,"description":184},"\u002Fterms\u002Fc\u002Fchange-data-capture","advanced","Change Data Capture (CDC) watches your database for changes and streams them as events.",{"title":169,"path":186,"acronym":6,"category":159,"difficulty":161,"description":187},"\u002Fterms\u002Fr\u002Fredis","Redis is an incredibly fast database that lives entirely in memory (RAM). It's used as a cache, a session store, and a message queue.",1792528069490]