[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-trigger-dev-staff-engineering-skills-cache-invalidation":3,"mdc--bqe9g-key":37,"related-org-trigger-dev-staff-engineering-skills-cache-invalidation":3826,"related-repo-trigger-dev-staff-engineering-skills-cache-invalidation":3986},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":12,"stars":26,"repoUrl":27,"updatedAt":28,"license":29,"forks":30,"topics":31,"repo":32,"sourceUrl":35,"mdContent":36},"staff-engineering-skills-cache-invalidation","implement cache invalidation strategies","Prevent stale data bugs caused by missing or incomplete cache invalidation. Use when adding caching layers (Redis, in-memory Map, CDN, HTTP cache headers), optimizing read performance, or reviewing code that caches query results, API responses, or computed values. Activates on patterns like cache.set without cache.delete on write paths, unbounded Map\u002Fobject caches, TTL-only invalidation on security-sensitive data, Cache-Control headers on mutable content, or any caching where the write path doesn't invalidate the read cache.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},"trigger-dev","Trigger.dev","https:\u002F\u002Fpexgzepcugksgbtrxkhf.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Forg-logos\u002Ftrigger-dev.jpg","triggerdotdev",[13,17,20,23],{"name":14,"slug":15,"type":16},"Performance","performance","tag",{"name":18,"slug":19,"type":16},"Architecture","architecture",{"name":21,"slug":22,"type":16},"Engineering","engineering",{"name":24,"slug":25,"type":16},"Caching","caching",3,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fstaff-engineering-skills","2026-06-17T08:40:45.194583",null,1,[],{"repoUrl":27,"stars":26,"forks":30,"topics":33,"description":34},[],"Skills that give AI   coding agents staff-engineer instincts: recognizing and avoiding production failure modes like cardinality, idempotency, and race conditions.","https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fstaff-engineering-skills\u002Ftree\u002FHEAD\u002Fskills\u002Fstaff-engineering-skills-cache-invalidation","---\nname: staff-engineering-skills-cache-invalidation\ndescription: Prevent stale data bugs caused by missing or incomplete cache invalidation. Use when adding caching layers (Redis, in-memory Map, CDN, HTTP cache headers), optimizing read performance, or reviewing code that caches query results, API responses, or computed values. Activates on patterns like cache.set without cache.delete on write paths, unbounded Map\u002Fobject caches, TTL-only invalidation on security-sensitive data, Cache-Control headers on mutable content, or any caching where the write path doesn't invalidate the read cache.\n---\n\n# Cache Invalidation Trap\n\nYou added a cache for performance. Now users see stale data. Before caching anything, ask: **when the source data changes, how does every copy get updated or discarded?**\n\n## The Fundamental Problem\n\nA cache is a copy, and copies diverge from the source. Every cache creates a consistency obligation: when the source changes, you must update or discard the copy. If you can't answer \"how does this cache learn that the source changed?\", you don't have a caching strategy -- you have a stale data bug with a variable delay.\n\n## The Cache Hierarchy\n\nData passes through multiple cache layers; invalidating one doesn't invalidate the others. Invalidate the application cache but not the CDN (or the CDN but not the browser), and the stale layer keeps serving old data.\n\n| Layer | Control | Invalidation | Risk |\n|-------|---------|-------------|------|\n| **Browser cache** | Limited (Cache-Control headers) | Can't force purge from server | Stale until user refreshes |\n| **CDN** | Purge API, surrogate keys | Propagation delay (seconds) | Millions served stale data |\n| **Reverse proxy** | Full control | Direct purge | Stale responses after deploy |\n| **Application cache** (Redis, in-memory) | Full control | Event-driven or TTL | Process-local caches diverge across instances |\n| **ORM\u002Fquery cache** | Framework config | Often implicit, hard to invalidate | Stale reads after direct DB writes |\n\n## Detection: When You're Creating a Stale Cache\n\n**Stop and fix if you see:**\n\n1. **`cache.set()` in the read path but no `cache.delete()` in the write path** -- writes don't invalidate reads; the cache serves old data until TTL or restart.\n\n2. **`new Map()` or `{}` used as a cache with no size limit** -- grows forever. Staleness bug AND memory leak. Use LRU with a max size.\n\n3. **TTL-only invalidation on security-sensitive data** (permissions, access tokens, feature flags) -- a revoked admin keeps access for the entire TTL. Invalidate on change, not on timer.\n\n4. **`Cache-Control: max-age=86400` on mutable data** -- the browser won't ask the server for 24 hours. Can't fix server-side; the only escape is changing the URL.\n\n5. **Cache key that doesn't include all variables affecting the value** -- `product:${id}` when the response varies by locale, role, or currency. Users see each other's cached content.\n\n6. **Caching at the application level while also serving through a CDN** -- two caches, probably one invalidation path. Invalidate Redis, the CDN still has the old version.\n\n7. **Write path that bypasses cache invalidation** -- the API invalidates on update, but a background job or admin tool writes directly to the DB. The cache never learns.\n\n## Patterns\n\n### Content-addressed caching (best -- no invalidation needed)\n\nThe cache key IS the content hash, so when content changes the key changes and old entries evict naturally via LRU.\n\n```typescript\nfunction getAssetUrl(content: Buffer): string {\n  const hash = crypto.createHash(\"sha256\").update(content).digest(\"hex\").slice(0, 16);\n  return `\u002Fassets\u002F${hash}.js`; \u002F\u002F serve with: Cache-Control: public, max-age=31536000, immutable\n}\n```\n\nThis is why build tools hash filenames (`main.a1b2c3d4.js`) while serving the referencing HTML with `no-cache`. **Use whenever the cached value is derived deterministically from its inputs.**\n\n### Cache-aside with event-driven invalidation\n\n```typescript\nconst CACHE_TTL = 300; \u002F\u002F safety net, not the primary mechanism\n\nasync function getProfile(userId: string): Promise\u003CUserProfile> {\n  const cached = await redis.get(`profile:${userId}`);\n  if (cached) return JSON.parse(cached);\n\n  const profile = await db.users.findUnique({ where: { id: userId } });\n  await redis.setex(`profile:${userId}`, CACHE_TTL, JSON.stringify(profile));\n  return profile;\n}\n\nasync function updateProfile(userId: string, data: Partial\u003CUserProfile>) {\n  const updated = await db.users.update({ where: { id: userId }, data });\n  \u002F\u002F Write-through: set to the known-correct value from the write\n  await redis.setex(`profile:${userId}`, CACHE_TTL, JSON.stringify(updated));\n  \u002F\u002F For other instances with local caches, publish invalidation\n  await redis.publish(\"cache-invalidation\", JSON.stringify({ type: \"profile\", id: userId }));\n}\n```\n\n- **Write-through** (set to new value) beats **delete** (let next read repopulate): delete risks repopulation from a stale replica -- see the Consistency Models skill.\n- The TTL is a **safety net** that catches writes bypassing the invalidation path (admin tools, migrations, background jobs).\n- Multiple instances with local caches need a pub\u002Fsub invalidation channel.\n\n### Bounded in-memory cache with LRU\n\nNever use a plain `Map` as a cache. Always use an LRU (or similar) with a size limit and TTL. `allowStale: true` gives stale-while-revalidate: the caller gets the old value immediately while the fresh value loads in the background.\n\n```typescript\nimport { LRUCache } from \"lru-cache\";\n\nconst profileCache = new LRUCache\u003Cstring, UserProfile>({\n  max: 10_000,\n  ttl: 5 * 60 * 1000,\n  allowStale: true,\n  fetchMethod: async (userId) => db.users.findUnique({ where: { id: userId } }),\n});\n\nasync function getProfile(userId: string): Promise\u003CUserProfile> {\n  return profileCache.fetch(userId);\n}\n```\n\n### Cache stampede prevention (single-flight)\n\nWhen a popular entry expires, hundreds of requests see a miss simultaneously and all hit the database. Coalesce them into one.\n\n```typescript\nconst inFlight = new Map\u003Cstring, Promise\u003Cany>>();\n\nasync function getCached\u003CT>(key: string, fetcher: () => Promise\u003CT>, ttlSeconds: number): Promise\u003CT> {\n  const cached = await redis.get(key);\n  if (cached) return JSON.parse(cached);\n  if (inFlight.has(key)) return inFlight.get(key) as Promise\u003CT>; \u002F\u002F already fetching, wait for it\n\n  const promise = fetcher()\n    .then(async (result) => {\n      await redis.setex(key, ttlSeconds, JSON.stringify(result));\n      inFlight.delete(key);\n      return result;\n    })\n    .catch((err) => {\n      inFlight.delete(key);\n      throw err;\n    });\n\n  inFlight.set(key, promise);\n  return promise;\n}\n```\n\nThis works within a single process only. For multi-instance stampede prevention, use a distributed lock or probabilistic early expiration (each request has a small random chance of refreshing before TTL).\n\n### Cache key design\n\nEvery variable that affects the cached value must be in the key, or different contexts share data they shouldn't.\n\n```typescript\nconst key = `product:${productId}`;                                  \u002F\u002F BAD: ignores locale\u002Fcurrency\nconst key = `product:${productId}:locale:${locale}:currency:${currency}`;\nconst key = `dashboard:${userId}:${orgId}`;                          \u002F\u002F user-specific data\nconst key = `orders:${userId}:page:${page}:size:${pageSize}:sort:${sortBy}`; \u002F\u002F paginated data\n```\n\n## What to Cache Where\n\n| Data | Invalidation strategy | TTL | Notes |\n|------|----------------------|-----|-------|\n| Static assets (JS, CSS, images) | Content-addressed URL | Immutable (1 year) | No invalidation -- URL changes |\n| User profile (own) | Write-through on update | 5 min safety net | Must see own changes immediately |\n| User profile (others) | TTL-only | 5-15 min | Eventual consistency is fine |\n| Permissions \u002F access control | Invalidate on change | 30 sec safety net | Never TTL-only for security data |\n| Feature flags | Invalidate on change | 1 min safety net | Long TTL delays incident response |\n| Product catalog | Event-driven + TTL | 15 min | Flash sales need faster invalidation |\n| Search results | TTL-only | 1-5 min | Eventually consistent by nature |\n| API rate limit counters | N\u002FA (not a cache) | N\u002FA | Use Redis atomic ops, not caching |\n\n## Anti-Patterns\n\n```typescript\n\u002F\u002F No invalidation: cache written, never cleared\nfunction getUser(id) { \u002F* sets cache *\u002F }\nfunction updateUser(id, data) { \u002F* updates DB, doesn't touch cache *\u002F }\n\n\u002F\u002F Unbounded: grows until OOM\nconst queryCache = new Map\u003Cstring, any>();\n\n\u002F\u002F TTL on security data: revoked user keeps access for 15 minutes\nconst permCache = new Map();\nconst TTL = 15 * 60 * 1000;\n\n\u002F\u002F Delete-then-repopulate race: del, then another request reads a lagging replica and re-caches stale data\nawait redis.del(`user:${id}`);\n\n\u002F\u002F Cache key missing context: users see each other's locale-specific content\nawait redis.set(`product:${id}`, JSON.stringify(localizedProduct));\n```\n\n## Related Traps\n\n- **Consistency Models** -- cache staleness is a consistency problem. Write-through caching avoids the race where delete-then-repopulate reads from a stale replica. See the Consistency Models skill for read-after-write patterns.\n- **Memory Leaks** -- every unbounded cache is a memory leak. If it has no max size and no eviction policy, it grows until the process is killed.\n- **Thundering Herd** -- cache stampede (popular key expires, all requests hit the database simultaneously) is the thundering herd problem applied to caching. Single-flight and stale-while-revalidate prevent this.\n- **Denormalization** -- a cache is a form of denormalization. Every cached value is a copy that must be kept in sync with the source. The consistency obligation is the same.\n",{"data":38,"body":39},{"name":4,"description":6},{"type":40,"children":41},"root",[42,51,63,70,75,81,86,255,261,269,387,393,400,405,684,710,716,1568,1606,1612,1633,2054,2060,2065,2832,2837,2843,2848,3138,3144,3358,3364,3771,3777,3820],{"type":43,"tag":44,"props":45,"children":47},"element","h1",{"id":46},"cache-invalidation-trap",[48],{"type":49,"value":50},"text","Cache Invalidation Trap",{"type":43,"tag":52,"props":53,"children":54},"p",{},[55,57],{"type":49,"value":56},"You added a cache for performance. Now users see stale data. Before caching anything, ask: ",{"type":43,"tag":58,"props":59,"children":60},"strong",{},[61],{"type":49,"value":62},"when the source data changes, how does every copy get updated or discarded?",{"type":43,"tag":64,"props":65,"children":67},"h2",{"id":66},"the-fundamental-problem",[68],{"type":49,"value":69},"The Fundamental Problem",{"type":43,"tag":52,"props":71,"children":72},{},[73],{"type":49,"value":74},"A cache is a copy, and copies diverge from the source. Every cache creates a consistency obligation: when the source changes, you must update or discard the copy. If you can't answer \"how does this cache learn that the source changed?\", you don't have a caching strategy -- you have a stale data bug with a variable delay.",{"type":43,"tag":64,"props":76,"children":78},{"id":77},"the-cache-hierarchy",[79],{"type":49,"value":80},"The Cache Hierarchy",{"type":43,"tag":52,"props":82,"children":83},{},[84],{"type":49,"value":85},"Data passes through multiple cache layers; invalidating one doesn't invalidate the others. Invalidate the application cache but not the CDN (or the CDN but not the browser), and the stale layer keeps serving old data.",{"type":43,"tag":87,"props":88,"children":89},"table",{},[90,119],{"type":43,"tag":91,"props":92,"children":93},"thead",{},[94],{"type":43,"tag":95,"props":96,"children":97},"tr",{},[98,104,109,114],{"type":43,"tag":99,"props":100,"children":101},"th",{},[102],{"type":49,"value":103},"Layer",{"type":43,"tag":99,"props":105,"children":106},{},[107],{"type":49,"value":108},"Control",{"type":43,"tag":99,"props":110,"children":111},{},[112],{"type":49,"value":113},"Invalidation",{"type":43,"tag":99,"props":115,"children":116},{},[117],{"type":49,"value":118},"Risk",{"type":43,"tag":120,"props":121,"children":122},"tbody",{},[123,150,176,202,229],{"type":43,"tag":95,"props":124,"children":125},{},[126,135,140,145],{"type":43,"tag":127,"props":128,"children":129},"td",{},[130],{"type":43,"tag":58,"props":131,"children":132},{},[133],{"type":49,"value":134},"Browser cache",{"type":43,"tag":127,"props":136,"children":137},{},[138],{"type":49,"value":139},"Limited (Cache-Control headers)",{"type":43,"tag":127,"props":141,"children":142},{},[143],{"type":49,"value":144},"Can't force purge from server",{"type":43,"tag":127,"props":146,"children":147},{},[148],{"type":49,"value":149},"Stale until user refreshes",{"type":43,"tag":95,"props":151,"children":152},{},[153,161,166,171],{"type":43,"tag":127,"props":154,"children":155},{},[156],{"type":43,"tag":58,"props":157,"children":158},{},[159],{"type":49,"value":160},"CDN",{"type":43,"tag":127,"props":162,"children":163},{},[164],{"type":49,"value":165},"Purge API, surrogate keys",{"type":43,"tag":127,"props":167,"children":168},{},[169],{"type":49,"value":170},"Propagation delay (seconds)",{"type":43,"tag":127,"props":172,"children":173},{},[174],{"type":49,"value":175},"Millions served stale data",{"type":43,"tag":95,"props":177,"children":178},{},[179,187,192,197],{"type":43,"tag":127,"props":180,"children":181},{},[182],{"type":43,"tag":58,"props":183,"children":184},{},[185],{"type":49,"value":186},"Reverse proxy",{"type":43,"tag":127,"props":188,"children":189},{},[190],{"type":49,"value":191},"Full control",{"type":43,"tag":127,"props":193,"children":194},{},[195],{"type":49,"value":196},"Direct purge",{"type":43,"tag":127,"props":198,"children":199},{},[200],{"type":49,"value":201},"Stale responses after deploy",{"type":43,"tag":95,"props":203,"children":204},{},[205,215,219,224],{"type":43,"tag":127,"props":206,"children":207},{},[208,213],{"type":43,"tag":58,"props":209,"children":210},{},[211],{"type":49,"value":212},"Application cache",{"type":49,"value":214}," (Redis, in-memory)",{"type":43,"tag":127,"props":216,"children":217},{},[218],{"type":49,"value":191},{"type":43,"tag":127,"props":220,"children":221},{},[222],{"type":49,"value":223},"Event-driven or TTL",{"type":43,"tag":127,"props":225,"children":226},{},[227],{"type":49,"value":228},"Process-local caches diverge across instances",{"type":43,"tag":95,"props":230,"children":231},{},[232,240,245,250],{"type":43,"tag":127,"props":233,"children":234},{},[235],{"type":43,"tag":58,"props":236,"children":237},{},[238],{"type":49,"value":239},"ORM\u002Fquery cache",{"type":43,"tag":127,"props":241,"children":242},{},[243],{"type":49,"value":244},"Framework config",{"type":43,"tag":127,"props":246,"children":247},{},[248],{"type":49,"value":249},"Often implicit, hard to invalidate",{"type":43,"tag":127,"props":251,"children":252},{},[253],{"type":49,"value":254},"Stale reads after direct DB writes",{"type":43,"tag":64,"props":256,"children":258},{"id":257},"detection-when-youre-creating-a-stale-cache",[259],{"type":49,"value":260},"Detection: When You're Creating a Stale Cache",{"type":43,"tag":52,"props":262,"children":263},{},[264],{"type":43,"tag":58,"props":265,"children":266},{},[267],{"type":49,"value":268},"Stop and fix if you see:",{"type":43,"tag":270,"props":271,"children":272},"ol",{},[273,299,323,333,349,367,377],{"type":43,"tag":274,"props":275,"children":276},"li",{},[277,297],{"type":43,"tag":58,"props":278,"children":279},{},[280,287,289,295],{"type":43,"tag":281,"props":282,"children":284},"code",{"className":283},[],[285],{"type":49,"value":286},"cache.set()",{"type":49,"value":288}," in the read path but no ",{"type":43,"tag":281,"props":290,"children":292},{"className":291},[],[293],{"type":49,"value":294},"cache.delete()",{"type":49,"value":296}," in the write path",{"type":49,"value":298}," -- writes don't invalidate reads; the cache serves old data until TTL or restart.",{"type":43,"tag":274,"props":300,"children":301},{},[302,321],{"type":43,"tag":58,"props":303,"children":304},{},[305,311,313,319],{"type":43,"tag":281,"props":306,"children":308},{"className":307},[],[309],{"type":49,"value":310},"new Map()",{"type":49,"value":312}," or ",{"type":43,"tag":281,"props":314,"children":316},{"className":315},[],[317],{"type":49,"value":318},"{}",{"type":49,"value":320}," used as a cache with no size limit",{"type":49,"value":322}," -- grows forever. Staleness bug AND memory leak. Use LRU with a max size.",{"type":43,"tag":274,"props":324,"children":325},{},[326,331],{"type":43,"tag":58,"props":327,"children":328},{},[329],{"type":49,"value":330},"TTL-only invalidation on security-sensitive data",{"type":49,"value":332}," (permissions, access tokens, feature flags) -- a revoked admin keeps access for the entire TTL. Invalidate on change, not on timer.",{"type":43,"tag":274,"props":334,"children":335},{},[336,347],{"type":43,"tag":58,"props":337,"children":338},{},[339,345],{"type":43,"tag":281,"props":340,"children":342},{"className":341},[],[343],{"type":49,"value":344},"Cache-Control: max-age=86400",{"type":49,"value":346}," on mutable data",{"type":49,"value":348}," -- the browser won't ask the server for 24 hours. Can't fix server-side; the only escape is changing the URL.",{"type":43,"tag":274,"props":350,"children":351},{},[352,357,359,365],{"type":43,"tag":58,"props":353,"children":354},{},[355],{"type":49,"value":356},"Cache key that doesn't include all variables affecting the value",{"type":49,"value":358}," -- ",{"type":43,"tag":281,"props":360,"children":362},{"className":361},[],[363],{"type":49,"value":364},"product:${id}",{"type":49,"value":366}," when the response varies by locale, role, or currency. Users see each other's cached content.",{"type":43,"tag":274,"props":368,"children":369},{},[370,375],{"type":43,"tag":58,"props":371,"children":372},{},[373],{"type":49,"value":374},"Caching at the application level while also serving through a CDN",{"type":49,"value":376}," -- two caches, probably one invalidation path. Invalidate Redis, the CDN still has the old version.",{"type":43,"tag":274,"props":378,"children":379},{},[380,385],{"type":43,"tag":58,"props":381,"children":382},{},[383],{"type":49,"value":384},"Write path that bypasses cache invalidation",{"type":49,"value":386}," -- the API invalidates on update, but a background job or admin tool writes directly to the DB. The cache never learns.",{"type":43,"tag":64,"props":388,"children":390},{"id":389},"patterns",[391],{"type":49,"value":392},"Patterns",{"type":43,"tag":394,"props":395,"children":397},"h3",{"id":396},"content-addressed-caching-best-no-invalidation-needed",[398],{"type":49,"value":399},"Content-addressed caching (best -- no invalidation needed)",{"type":43,"tag":52,"props":401,"children":402},{},[403],{"type":49,"value":404},"The cache key IS the content hash, so when content changes the key changes and old entries evict naturally via LRU.",{"type":43,"tag":406,"props":407,"children":412},"pre",{"className":408,"code":409,"language":410,"meta":411,"style":411},"language-typescript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","function getAssetUrl(content: Buffer): string {\n  const hash = crypto.createHash(\"sha256\").update(content).digest(\"hex\").slice(0, 16);\n  return `\u002Fassets\u002F${hash}.js`; \u002F\u002F serve with: Cache-Control: public, max-age=31536000, immutable\n}\n","typescript","",[413],{"type":43,"tag":281,"props":414,"children":415},{"__ignoreMap":411},[416,471,620,675],{"type":43,"tag":417,"props":418,"children":420},"span",{"class":419,"line":30},"line",[421,427,433,439,445,450,456,461,466],{"type":43,"tag":417,"props":422,"children":424},{"style":423},"--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA",[425],{"type":49,"value":426},"function",{"type":43,"tag":417,"props":428,"children":430},{"style":429},"--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF",[431],{"type":49,"value":432}," getAssetUrl",{"type":43,"tag":417,"props":434,"children":436},{"style":435},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF",[437],{"type":49,"value":438},"(",{"type":43,"tag":417,"props":440,"children":442},{"style":441},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic",[443],{"type":49,"value":444},"content",{"type":43,"tag":417,"props":446,"children":447},{"style":435},[448],{"type":49,"value":449},":",{"type":43,"tag":417,"props":451,"children":453},{"style":452},"--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B",[454],{"type":49,"value":455}," Buffer",{"type":43,"tag":417,"props":457,"children":458},{"style":435},[459],{"type":49,"value":460},"):",{"type":43,"tag":417,"props":462,"children":463},{"style":452},[464],{"type":49,"value":465}," string",{"type":43,"tag":417,"props":467,"children":468},{"style":435},[469],{"type":49,"value":470}," {\n",{"type":43,"tag":417,"props":472,"children":474},{"class":419,"line":473},2,[475,480,486,491,496,501,506,511,516,522,526,531,535,540,544,548,552,556,561,565,569,574,578,582,586,591,595,601,606,611,615],{"type":43,"tag":417,"props":476,"children":477},{"style":423},[478],{"type":49,"value":479},"  const",{"type":43,"tag":417,"props":481,"children":483},{"style":482},"--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8",[484],{"type":49,"value":485}," hash",{"type":43,"tag":417,"props":487,"children":488},{"style":435},[489],{"type":49,"value":490}," =",{"type":43,"tag":417,"props":492,"children":493},{"style":482},[494],{"type":49,"value":495}," crypto",{"type":43,"tag":417,"props":497,"children":498},{"style":435},[499],{"type":49,"value":500},".",{"type":43,"tag":417,"props":502,"children":503},{"style":429},[504],{"type":49,"value":505},"createHash",{"type":43,"tag":417,"props":507,"children":509},{"style":508},"--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178",[510],{"type":49,"value":438},{"type":43,"tag":417,"props":512,"children":513},{"style":435},[514],{"type":49,"value":515},"\"",{"type":43,"tag":417,"props":517,"children":519},{"style":518},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[520],{"type":49,"value":521},"sha256",{"type":43,"tag":417,"props":523,"children":524},{"style":435},[525],{"type":49,"value":515},{"type":43,"tag":417,"props":527,"children":528},{"style":508},[529],{"type":49,"value":530},")",{"type":43,"tag":417,"props":532,"children":533},{"style":435},[534],{"type":49,"value":500},{"type":43,"tag":417,"props":536,"children":537},{"style":429},[538],{"type":49,"value":539},"update",{"type":43,"tag":417,"props":541,"children":542},{"style":508},[543],{"type":49,"value":438},{"type":43,"tag":417,"props":545,"children":546},{"style":482},[547],{"type":49,"value":444},{"type":43,"tag":417,"props":549,"children":550},{"style":508},[551],{"type":49,"value":530},{"type":43,"tag":417,"props":553,"children":554},{"style":435},[555],{"type":49,"value":500},{"type":43,"tag":417,"props":557,"children":558},{"style":429},[559],{"type":49,"value":560},"digest",{"type":43,"tag":417,"props":562,"children":563},{"style":508},[564],{"type":49,"value":438},{"type":43,"tag":417,"props":566,"children":567},{"style":435},[568],{"type":49,"value":515},{"type":43,"tag":417,"props":570,"children":571},{"style":518},[572],{"type":49,"value":573},"hex",{"type":43,"tag":417,"props":575,"children":576},{"style":435},[577],{"type":49,"value":515},{"type":43,"tag":417,"props":579,"children":580},{"style":508},[581],{"type":49,"value":530},{"type":43,"tag":417,"props":583,"children":584},{"style":435},[585],{"type":49,"value":500},{"type":43,"tag":417,"props":587,"children":588},{"style":429},[589],{"type":49,"value":590},"slice",{"type":43,"tag":417,"props":592,"children":593},{"style":508},[594],{"type":49,"value":438},{"type":43,"tag":417,"props":596,"children":598},{"style":597},"--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C",[599],{"type":49,"value":600},"0",{"type":43,"tag":417,"props":602,"children":603},{"style":435},[604],{"type":49,"value":605},",",{"type":43,"tag":417,"props":607,"children":608},{"style":597},[609],{"type":49,"value":610}," 16",{"type":43,"tag":417,"props":612,"children":613},{"style":508},[614],{"type":49,"value":530},{"type":43,"tag":417,"props":616,"children":617},{"style":435},[618],{"type":49,"value":619},";\n",{"type":43,"tag":417,"props":621,"children":622},{"class":419,"line":26},[623,629,634,639,644,649,654,659,664,669],{"type":43,"tag":417,"props":624,"children":626},{"style":625},"--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic",[627],{"type":49,"value":628},"  return",{"type":43,"tag":417,"props":630,"children":631},{"style":435},[632],{"type":49,"value":633}," `",{"type":43,"tag":417,"props":635,"children":636},{"style":518},[637],{"type":49,"value":638},"\u002Fassets\u002F",{"type":43,"tag":417,"props":640,"children":641},{"style":435},[642],{"type":49,"value":643},"${",{"type":43,"tag":417,"props":645,"children":646},{"style":482},[647],{"type":49,"value":648},"hash",{"type":43,"tag":417,"props":650,"children":651},{"style":435},[652],{"type":49,"value":653},"}",{"type":43,"tag":417,"props":655,"children":656},{"style":518},[657],{"type":49,"value":658},".js",{"type":43,"tag":417,"props":660,"children":661},{"style":435},[662],{"type":49,"value":663},"`",{"type":43,"tag":417,"props":665,"children":666},{"style":435},[667],{"type":49,"value":668},";",{"type":43,"tag":417,"props":670,"children":672},{"style":671},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic",[673],{"type":49,"value":674}," \u002F\u002F serve with: Cache-Control: public, max-age=31536000, immutable\n",{"type":43,"tag":417,"props":676,"children":678},{"class":419,"line":677},4,[679],{"type":43,"tag":417,"props":680,"children":681},{"style":435},[682],{"type":49,"value":683},"}\n",{"type":43,"tag":52,"props":685,"children":686},{},[687,689,695,697,703,705],{"type":49,"value":688},"This is why build tools hash filenames (",{"type":43,"tag":281,"props":690,"children":692},{"className":691},[],[693],{"type":49,"value":694},"main.a1b2c3d4.js",{"type":49,"value":696},") while serving the referencing HTML with ",{"type":43,"tag":281,"props":698,"children":700},{"className":699},[],[701],{"type":49,"value":702},"no-cache",{"type":49,"value":704},". ",{"type":43,"tag":58,"props":706,"children":707},{},[708],{"type":49,"value":709},"Use whenever the cached value is derived deterministically from its inputs.",{"type":43,"tag":394,"props":711,"children":713},{"id":712},"cache-aside-with-event-driven-invalidation",[714],{"type":49,"value":715},"Cache-aside with event-driven invalidation",{"type":43,"tag":406,"props":717,"children":719},{"className":408,"code":718,"language":410,"meta":411,"style":411},"const CACHE_TTL = 300; \u002F\u002F safety net, not the primary mechanism\n\nasync function getProfile(userId: string): Promise\u003CUserProfile> {\n  const cached = await redis.get(`profile:${userId}`);\n  if (cached) return JSON.parse(cached);\n\n  const profile = await db.users.findUnique({ where: { id: userId } });\n  await redis.setex(`profile:${userId}`, CACHE_TTL, JSON.stringify(profile));\n  return profile;\n}\n\nasync function updateProfile(userId: string, data: Partial\u003CUserProfile>) {\n  const updated = await db.users.update({ where: { id: userId }, data });\n  \u002F\u002F Write-through: set to the known-correct value from the write\n  await redis.setex(`profile:${userId}`, CACHE_TTL, JSON.stringify(updated));\n  \u002F\u002F For other instances with local caches, publish invalidation\n  await redis.publish(\"cache-invalidation\", JSON.stringify({ type: \"profile\", id: userId }));\n}\n",[720],{"type":43,"tag":281,"props":721,"children":722},{"__ignoreMap":411},[723,755,764,827,896,955,963,1061,1151,1167,1175,1183,1251,1345,1354,1439,1448,1560],{"type":43,"tag":417,"props":724,"children":725},{"class":419,"line":30},[726,731,736,741,746,750],{"type":43,"tag":417,"props":727,"children":728},{"style":423},[729],{"type":49,"value":730},"const",{"type":43,"tag":417,"props":732,"children":733},{"style":482},[734],{"type":49,"value":735}," CACHE_TTL ",{"type":43,"tag":417,"props":737,"children":738},{"style":435},[739],{"type":49,"value":740},"=",{"type":43,"tag":417,"props":742,"children":743},{"style":597},[744],{"type":49,"value":745}," 300",{"type":43,"tag":417,"props":747,"children":748},{"style":435},[749],{"type":49,"value":668},{"type":43,"tag":417,"props":751,"children":752},{"style":671},[753],{"type":49,"value":754}," \u002F\u002F safety net, not the primary mechanism\n",{"type":43,"tag":417,"props":756,"children":757},{"class":419,"line":473},[758],{"type":43,"tag":417,"props":759,"children":761},{"emptyLinePlaceholder":760},true,[762],{"type":49,"value":763},"\n",{"type":43,"tag":417,"props":765,"children":766},{"class":419,"line":26},[767,772,777,782,786,791,795,799,803,808,813,818,823],{"type":43,"tag":417,"props":768,"children":769},{"style":423},[770],{"type":49,"value":771},"async",{"type":43,"tag":417,"props":773,"children":774},{"style":423},[775],{"type":49,"value":776}," function",{"type":43,"tag":417,"props":778,"children":779},{"style":429},[780],{"type":49,"value":781}," getProfile",{"type":43,"tag":417,"props":783,"children":784},{"style":435},[785],{"type":49,"value":438},{"type":43,"tag":417,"props":787,"children":788},{"style":441},[789],{"type":49,"value":790},"userId",{"type":43,"tag":417,"props":792,"children":793},{"style":435},[794],{"type":49,"value":449},{"type":43,"tag":417,"props":796,"children":797},{"style":452},[798],{"type":49,"value":465},{"type":43,"tag":417,"props":800,"children":801},{"style":435},[802],{"type":49,"value":460},{"type":43,"tag":417,"props":804,"children":805},{"style":452},[806],{"type":49,"value":807}," Promise",{"type":43,"tag":417,"props":809,"children":810},{"style":435},[811],{"type":49,"value":812},"\u003C",{"type":43,"tag":417,"props":814,"children":815},{"style":452},[816],{"type":49,"value":817},"UserProfile",{"type":43,"tag":417,"props":819,"children":820},{"style":435},[821],{"type":49,"value":822},">",{"type":43,"tag":417,"props":824,"children":825},{"style":435},[826],{"type":49,"value":470},{"type":43,"tag":417,"props":828,"children":829},{"class":419,"line":677},[830,834,839,843,848,853,857,862,866,870,875,879,883,888,892],{"type":43,"tag":417,"props":831,"children":832},{"style":423},[833],{"type":49,"value":479},{"type":43,"tag":417,"props":835,"children":836},{"style":482},[837],{"type":49,"value":838}," cached",{"type":43,"tag":417,"props":840,"children":841},{"style":435},[842],{"type":49,"value":490},{"type":43,"tag":417,"props":844,"children":845},{"style":625},[846],{"type":49,"value":847}," await",{"type":43,"tag":417,"props":849,"children":850},{"style":482},[851],{"type":49,"value":852}," redis",{"type":43,"tag":417,"props":854,"children":855},{"style":435},[856],{"type":49,"value":500},{"type":43,"tag":417,"props":858,"children":859},{"style":429},[860],{"type":49,"value":861},"get",{"type":43,"tag":417,"props":863,"children":864},{"style":508},[865],{"type":49,"value":438},{"type":43,"tag":417,"props":867,"children":868},{"style":435},[869],{"type":49,"value":663},{"type":43,"tag":417,"props":871,"children":872},{"style":518},[873],{"type":49,"value":874},"profile:",{"type":43,"tag":417,"props":876,"children":877},{"style":435},[878],{"type":49,"value":643},{"type":43,"tag":417,"props":880,"children":881},{"style":482},[882],{"type":49,"value":790},{"type":43,"tag":417,"props":884,"children":885},{"style":435},[886],{"type":49,"value":887},"}`",{"type":43,"tag":417,"props":889,"children":890},{"style":508},[891],{"type":49,"value":530},{"type":43,"tag":417,"props":893,"children":894},{"style":435},[895],{"type":49,"value":619},{"type":43,"tag":417,"props":897,"children":899},{"class":419,"line":898},5,[900,905,910,915,920,925,930,934,939,943,947,951],{"type":43,"tag":417,"props":901,"children":902},{"style":625},[903],{"type":49,"value":904},"  if",{"type":43,"tag":417,"props":906,"children":907},{"style":508},[908],{"type":49,"value":909}," (",{"type":43,"tag":417,"props":911,"children":912},{"style":482},[913],{"type":49,"value":914},"cached",{"type":43,"tag":417,"props":916,"children":917},{"style":508},[918],{"type":49,"value":919},") ",{"type":43,"tag":417,"props":921,"children":922},{"style":625},[923],{"type":49,"value":924},"return",{"type":43,"tag":417,"props":926,"children":927},{"style":482},[928],{"type":49,"value":929}," JSON",{"type":43,"tag":417,"props":931,"children":932},{"style":435},[933],{"type":49,"value":500},{"type":43,"tag":417,"props":935,"children":936},{"style":429},[937],{"type":49,"value":938},"parse",{"type":43,"tag":417,"props":940,"children":941},{"style":508},[942],{"type":49,"value":438},{"type":43,"tag":417,"props":944,"children":945},{"style":482},[946],{"type":49,"value":914},{"type":43,"tag":417,"props":948,"children":949},{"style":508},[950],{"type":49,"value":530},{"type":43,"tag":417,"props":952,"children":953},{"style":435},[954],{"type":49,"value":619},{"type":43,"tag":417,"props":956,"children":958},{"class":419,"line":957},6,[959],{"type":43,"tag":417,"props":960,"children":961},{"emptyLinePlaceholder":760},[962],{"type":49,"value":763},{"type":43,"tag":417,"props":964,"children":966},{"class":419,"line":965},7,[967,971,976,980,984,989,993,998,1002,1007,1011,1016,1021,1025,1030,1035,1039,1044,1049,1053,1057],{"type":43,"tag":417,"props":968,"children":969},{"style":423},[970],{"type":49,"value":479},{"type":43,"tag":417,"props":972,"children":973},{"style":482},[974],{"type":49,"value":975}," profile",{"type":43,"tag":417,"props":977,"children":978},{"style":435},[979],{"type":49,"value":490},{"type":43,"tag":417,"props":981,"children":982},{"style":625},[983],{"type":49,"value":847},{"type":43,"tag":417,"props":985,"children":986},{"style":482},[987],{"type":49,"value":988}," db",{"type":43,"tag":417,"props":990,"children":991},{"style":435},[992],{"type":49,"value":500},{"type":43,"tag":417,"props":994,"children":995},{"style":482},[996],{"type":49,"value":997},"users",{"type":43,"tag":417,"props":999,"children":1000},{"style":435},[1001],{"type":49,"value":500},{"type":43,"tag":417,"props":1003,"children":1004},{"style":429},[1005],{"type":49,"value":1006},"findUnique",{"type":43,"tag":417,"props":1008,"children":1009},{"style":508},[1010],{"type":49,"value":438},{"type":43,"tag":417,"props":1012,"children":1013},{"style":435},[1014],{"type":49,"value":1015},"{",{"type":43,"tag":417,"props":1017,"children":1018},{"style":508},[1019],{"type":49,"value":1020}," where",{"type":43,"tag":417,"props":1022,"children":1023},{"style":435},[1024],{"type":49,"value":449},{"type":43,"tag":417,"props":1026,"children":1027},{"style":435},[1028],{"type":49,"value":1029}," {",{"type":43,"tag":417,"props":1031,"children":1032},{"style":508},[1033],{"type":49,"value":1034}," id",{"type":43,"tag":417,"props":1036,"children":1037},{"style":435},[1038],{"type":49,"value":449},{"type":43,"tag":417,"props":1040,"children":1041},{"style":482},[1042],{"type":49,"value":1043}," userId",{"type":43,"tag":417,"props":1045,"children":1046},{"style":435},[1047],{"type":49,"value":1048}," }",{"type":43,"tag":417,"props":1050,"children":1051},{"style":435},[1052],{"type":49,"value":1048},{"type":43,"tag":417,"props":1054,"children":1055},{"style":508},[1056],{"type":49,"value":530},{"type":43,"tag":417,"props":1058,"children":1059},{"style":435},[1060],{"type":49,"value":619},{"type":43,"tag":417,"props":1062,"children":1064},{"class":419,"line":1063},8,[1065,1070,1074,1078,1083,1087,1091,1095,1099,1103,1107,1111,1116,1120,1124,1128,1133,1137,1142,1147],{"type":43,"tag":417,"props":1066,"children":1067},{"style":625},[1068],{"type":49,"value":1069},"  await",{"type":43,"tag":417,"props":1071,"children":1072},{"style":482},[1073],{"type":49,"value":852},{"type":43,"tag":417,"props":1075,"children":1076},{"style":435},[1077],{"type":49,"value":500},{"type":43,"tag":417,"props":1079,"children":1080},{"style":429},[1081],{"type":49,"value":1082},"setex",{"type":43,"tag":417,"props":1084,"children":1085},{"style":508},[1086],{"type":49,"value":438},{"type":43,"tag":417,"props":1088,"children":1089},{"style":435},[1090],{"type":49,"value":663},{"type":43,"tag":417,"props":1092,"children":1093},{"style":518},[1094],{"type":49,"value":874},{"type":43,"tag":417,"props":1096,"children":1097},{"style":435},[1098],{"type":49,"value":643},{"type":43,"tag":417,"props":1100,"children":1101},{"style":482},[1102],{"type":49,"value":790},{"type":43,"tag":417,"props":1104,"children":1105},{"style":435},[1106],{"type":49,"value":887},{"type":43,"tag":417,"props":1108,"children":1109},{"style":435},[1110],{"type":49,"value":605},{"type":43,"tag":417,"props":1112,"children":1113},{"style":482},[1114],{"type":49,"value":1115}," CACHE_TTL",{"type":43,"tag":417,"props":1117,"children":1118},{"style":435},[1119],{"type":49,"value":605},{"type":43,"tag":417,"props":1121,"children":1122},{"style":482},[1123],{"type":49,"value":929},{"type":43,"tag":417,"props":1125,"children":1126},{"style":435},[1127],{"type":49,"value":500},{"type":43,"tag":417,"props":1129,"children":1130},{"style":429},[1131],{"type":49,"value":1132},"stringify",{"type":43,"tag":417,"props":1134,"children":1135},{"style":508},[1136],{"type":49,"value":438},{"type":43,"tag":417,"props":1138,"children":1139},{"style":482},[1140],{"type":49,"value":1141},"profile",{"type":43,"tag":417,"props":1143,"children":1144},{"style":508},[1145],{"type":49,"value":1146},"))",{"type":43,"tag":417,"props":1148,"children":1149},{"style":435},[1150],{"type":49,"value":619},{"type":43,"tag":417,"props":1152,"children":1154},{"class":419,"line":1153},9,[1155,1159,1163],{"type":43,"tag":417,"props":1156,"children":1157},{"style":625},[1158],{"type":49,"value":628},{"type":43,"tag":417,"props":1160,"children":1161},{"style":482},[1162],{"type":49,"value":975},{"type":43,"tag":417,"props":1164,"children":1165},{"style":435},[1166],{"type":49,"value":619},{"type":43,"tag":417,"props":1168,"children":1170},{"class":419,"line":1169},10,[1171],{"type":43,"tag":417,"props":1172,"children":1173},{"style":435},[1174],{"type":49,"value":683},{"type":43,"tag":417,"props":1176,"children":1178},{"class":419,"line":1177},11,[1179],{"type":43,"tag":417,"props":1180,"children":1181},{"emptyLinePlaceholder":760},[1182],{"type":49,"value":763},{"type":43,"tag":417,"props":1184,"children":1186},{"class":419,"line":1185},12,[1187,1191,1195,1200,1204,1208,1212,1216,1220,1225,1229,1234,1238,1242,1247],{"type":43,"tag":417,"props":1188,"children":1189},{"style":423},[1190],{"type":49,"value":771},{"type":43,"tag":417,"props":1192,"children":1193},{"style":423},[1194],{"type":49,"value":776},{"type":43,"tag":417,"props":1196,"children":1197},{"style":429},[1198],{"type":49,"value":1199}," updateProfile",{"type":43,"tag":417,"props":1201,"children":1202},{"style":435},[1203],{"type":49,"value":438},{"type":43,"tag":417,"props":1205,"children":1206},{"style":441},[1207],{"type":49,"value":790},{"type":43,"tag":417,"props":1209,"children":1210},{"style":435},[1211],{"type":49,"value":449},{"type":43,"tag":417,"props":1213,"children":1214},{"style":452},[1215],{"type":49,"value":465},{"type":43,"tag":417,"props":1217,"children":1218},{"style":435},[1219],{"type":49,"value":605},{"type":43,"tag":417,"props":1221,"children":1222},{"style":441},[1223],{"type":49,"value":1224}," data",{"type":43,"tag":417,"props":1226,"children":1227},{"style":435},[1228],{"type":49,"value":449},{"type":43,"tag":417,"props":1230,"children":1231},{"style":452},[1232],{"type":49,"value":1233}," Partial",{"type":43,"tag":417,"props":1235,"children":1236},{"style":435},[1237],{"type":49,"value":812},{"type":43,"tag":417,"props":1239,"children":1240},{"style":452},[1241],{"type":49,"value":817},{"type":43,"tag":417,"props":1243,"children":1244},{"style":435},[1245],{"type":49,"value":1246},">)",{"type":43,"tag":417,"props":1248,"children":1249},{"style":435},[1250],{"type":49,"value":470},{"type":43,"tag":417,"props":1252,"children":1254},{"class":419,"line":1253},13,[1255,1259,1264,1268,1272,1276,1280,1284,1288,1292,1296,1300,1304,1308,1312,1316,1320,1324,1329,1333,1337,1341],{"type":43,"tag":417,"props":1256,"children":1257},{"style":423},[1258],{"type":49,"value":479},{"type":43,"tag":417,"props":1260,"children":1261},{"style":482},[1262],{"type":49,"value":1263}," updated",{"type":43,"tag":417,"props":1265,"children":1266},{"style":435},[1267],{"type":49,"value":490},{"type":43,"tag":417,"props":1269,"children":1270},{"style":625},[1271],{"type":49,"value":847},{"type":43,"tag":417,"props":1273,"children":1274},{"style":482},[1275],{"type":49,"value":988},{"type":43,"tag":417,"props":1277,"children":1278},{"style":435},[1279],{"type":49,"value":500},{"type":43,"tag":417,"props":1281,"children":1282},{"style":482},[1283],{"type":49,"value":997},{"type":43,"tag":417,"props":1285,"children":1286},{"style":435},[1287],{"type":49,"value":500},{"type":43,"tag":417,"props":1289,"children":1290},{"style":429},[1291],{"type":49,"value":539},{"type":43,"tag":417,"props":1293,"children":1294},{"style":508},[1295],{"type":49,"value":438},{"type":43,"tag":417,"props":1297,"children":1298},{"style":435},[1299],{"type":49,"value":1015},{"type":43,"tag":417,"props":1301,"children":1302},{"style":508},[1303],{"type":49,"value":1020},{"type":43,"tag":417,"props":1305,"children":1306},{"style":435},[1307],{"type":49,"value":449},{"type":43,"tag":417,"props":1309,"children":1310},{"style":435},[1311],{"type":49,"value":1029},{"type":43,"tag":417,"props":1313,"children":1314},{"style":508},[1315],{"type":49,"value":1034},{"type":43,"tag":417,"props":1317,"children":1318},{"style":435},[1319],{"type":49,"value":449},{"type":43,"tag":417,"props":1321,"children":1322},{"style":482},[1323],{"type":49,"value":1043},{"type":43,"tag":417,"props":1325,"children":1326},{"style":435},[1327],{"type":49,"value":1328}," },",{"type":43,"tag":417,"props":1330,"children":1331},{"style":482},[1332],{"type":49,"value":1224},{"type":43,"tag":417,"props":1334,"children":1335},{"style":435},[1336],{"type":49,"value":1048},{"type":43,"tag":417,"props":1338,"children":1339},{"style":508},[1340],{"type":49,"value":530},{"type":43,"tag":417,"props":1342,"children":1343},{"style":435},[1344],{"type":49,"value":619},{"type":43,"tag":417,"props":1346,"children":1348},{"class":419,"line":1347},14,[1349],{"type":43,"tag":417,"props":1350,"children":1351},{"style":671},[1352],{"type":49,"value":1353},"  \u002F\u002F Write-through: set to the known-correct value from the write\n",{"type":43,"tag":417,"props":1355,"children":1357},{"class":419,"line":1356},15,[1358,1362,1366,1370,1374,1378,1382,1386,1390,1394,1398,1402,1406,1410,1414,1418,1422,1426,1431,1435],{"type":43,"tag":417,"props":1359,"children":1360},{"style":625},[1361],{"type":49,"value":1069},{"type":43,"tag":417,"props":1363,"children":1364},{"style":482},[1365],{"type":49,"value":852},{"type":43,"tag":417,"props":1367,"children":1368},{"style":435},[1369],{"type":49,"value":500},{"type":43,"tag":417,"props":1371,"children":1372},{"style":429},[1373],{"type":49,"value":1082},{"type":43,"tag":417,"props":1375,"children":1376},{"style":508},[1377],{"type":49,"value":438},{"type":43,"tag":417,"props":1379,"children":1380},{"style":435},[1381],{"type":49,"value":663},{"type":43,"tag":417,"props":1383,"children":1384},{"style":518},[1385],{"type":49,"value":874},{"type":43,"tag":417,"props":1387,"children":1388},{"style":435},[1389],{"type":49,"value":643},{"type":43,"tag":417,"props":1391,"children":1392},{"style":482},[1393],{"type":49,"value":790},{"type":43,"tag":417,"props":1395,"children":1396},{"style":435},[1397],{"type":49,"value":887},{"type":43,"tag":417,"props":1399,"children":1400},{"style":435},[1401],{"type":49,"value":605},{"type":43,"tag":417,"props":1403,"children":1404},{"style":482},[1405],{"type":49,"value":1115},{"type":43,"tag":417,"props":1407,"children":1408},{"style":435},[1409],{"type":49,"value":605},{"type":43,"tag":417,"props":1411,"children":1412},{"style":482},[1413],{"type":49,"value":929},{"type":43,"tag":417,"props":1415,"children":1416},{"style":435},[1417],{"type":49,"value":500},{"type":43,"tag":417,"props":1419,"children":1420},{"style":429},[1421],{"type":49,"value":1132},{"type":43,"tag":417,"props":1423,"children":1424},{"style":508},[1425],{"type":49,"value":438},{"type":43,"tag":417,"props":1427,"children":1428},{"style":482},[1429],{"type":49,"value":1430},"updated",{"type":43,"tag":417,"props":1432,"children":1433},{"style":508},[1434],{"type":49,"value":1146},{"type":43,"tag":417,"props":1436,"children":1437},{"style":435},[1438],{"type":49,"value":619},{"type":43,"tag":417,"props":1440,"children":1442},{"class":419,"line":1441},16,[1443],{"type":43,"tag":417,"props":1444,"children":1445},{"style":671},[1446],{"type":49,"value":1447},"  \u002F\u002F For other instances with local caches, publish invalidation\n",{"type":43,"tag":417,"props":1449,"children":1451},{"class":419,"line":1450},17,[1452,1456,1460,1464,1469,1473,1477,1482,1486,1490,1494,1498,1502,1506,1510,1515,1519,1524,1528,1532,1536,1540,1544,1548,1552,1556],{"type":43,"tag":417,"props":1453,"children":1454},{"style":625},[1455],{"type":49,"value":1069},{"type":43,"tag":417,"props":1457,"children":1458},{"style":482},[1459],{"type":49,"value":852},{"type":43,"tag":417,"props":1461,"children":1462},{"style":435},[1463],{"type":49,"value":500},{"type":43,"tag":417,"props":1465,"children":1466},{"style":429},[1467],{"type":49,"value":1468},"publish",{"type":43,"tag":417,"props":1470,"children":1471},{"style":508},[1472],{"type":49,"value":438},{"type":43,"tag":417,"props":1474,"children":1475},{"style":435},[1476],{"type":49,"value":515},{"type":43,"tag":417,"props":1478,"children":1479},{"style":518},[1480],{"type":49,"value":1481},"cache-invalidation",{"type":43,"tag":417,"props":1483,"children":1484},{"style":435},[1485],{"type":49,"value":515},{"type":43,"tag":417,"props":1487,"children":1488},{"style":435},[1489],{"type":49,"value":605},{"type":43,"tag":417,"props":1491,"children":1492},{"style":482},[1493],{"type":49,"value":929},{"type":43,"tag":417,"props":1495,"children":1496},{"style":435},[1497],{"type":49,"value":500},{"type":43,"tag":417,"props":1499,"children":1500},{"style":429},[1501],{"type":49,"value":1132},{"type":43,"tag":417,"props":1503,"children":1504},{"style":508},[1505],{"type":49,"value":438},{"type":43,"tag":417,"props":1507,"children":1508},{"style":435},[1509],{"type":49,"value":1015},{"type":43,"tag":417,"props":1511,"children":1512},{"style":508},[1513],{"type":49,"value":1514}," type",{"type":43,"tag":417,"props":1516,"children":1517},{"style":435},[1518],{"type":49,"value":449},{"type":43,"tag":417,"props":1520,"children":1521},{"style":435},[1522],{"type":49,"value":1523}," \"",{"type":43,"tag":417,"props":1525,"children":1526},{"style":518},[1527],{"type":49,"value":1141},{"type":43,"tag":417,"props":1529,"children":1530},{"style":435},[1531],{"type":49,"value":515},{"type":43,"tag":417,"props":1533,"children":1534},{"style":435},[1535],{"type":49,"value":605},{"type":43,"tag":417,"props":1537,"children":1538},{"style":508},[1539],{"type":49,"value":1034},{"type":43,"tag":417,"props":1541,"children":1542},{"style":435},[1543],{"type":49,"value":449},{"type":43,"tag":417,"props":1545,"children":1546},{"style":482},[1547],{"type":49,"value":1043},{"type":43,"tag":417,"props":1549,"children":1550},{"style":435},[1551],{"type":49,"value":1048},{"type":43,"tag":417,"props":1553,"children":1554},{"style":508},[1555],{"type":49,"value":1146},{"type":43,"tag":417,"props":1557,"children":1558},{"style":435},[1559],{"type":49,"value":619},{"type":43,"tag":417,"props":1561,"children":1563},{"class":419,"line":1562},18,[1564],{"type":43,"tag":417,"props":1565,"children":1566},{"style":435},[1567],{"type":49,"value":683},{"type":43,"tag":1569,"props":1570,"children":1571},"ul",{},[1572,1589,1601],{"type":43,"tag":274,"props":1573,"children":1574},{},[1575,1580,1582,1587],{"type":43,"tag":58,"props":1576,"children":1577},{},[1578],{"type":49,"value":1579},"Write-through",{"type":49,"value":1581}," (set to new value) beats ",{"type":43,"tag":58,"props":1583,"children":1584},{},[1585],{"type":49,"value":1586},"delete",{"type":49,"value":1588}," (let next read repopulate): delete risks repopulation from a stale replica -- see the Consistency Models skill.",{"type":43,"tag":274,"props":1590,"children":1591},{},[1592,1594,1599],{"type":49,"value":1593},"The TTL is a ",{"type":43,"tag":58,"props":1595,"children":1596},{},[1597],{"type":49,"value":1598},"safety net",{"type":49,"value":1600}," that catches writes bypassing the invalidation path (admin tools, migrations, background jobs).",{"type":43,"tag":274,"props":1602,"children":1603},{},[1604],{"type":49,"value":1605},"Multiple instances with local caches need a pub\u002Fsub invalidation channel.",{"type":43,"tag":394,"props":1607,"children":1609},{"id":1608},"bounded-in-memory-cache-with-lru",[1610],{"type":49,"value":1611},"Bounded in-memory cache with LRU",{"type":43,"tag":52,"props":1613,"children":1614},{},[1615,1617,1623,1625,1631],{"type":49,"value":1616},"Never use a plain ",{"type":43,"tag":281,"props":1618,"children":1620},{"className":1619},[],[1621],{"type":49,"value":1622},"Map",{"type":49,"value":1624}," as a cache. Always use an LRU (or similar) with a size limit and TTL. ",{"type":43,"tag":281,"props":1626,"children":1628},{"className":1627},[],[1629],{"type":49,"value":1630},"allowStale: true",{"type":49,"value":1632}," gives stale-while-revalidate: the caller gets the old value immediately while the fresh value loads in the background.",{"type":43,"tag":406,"props":1634,"children":1636},{"className":408,"code":1635,"language":410,"meta":411,"style":411},"import { LRUCache } from \"lru-cache\";\n\nconst profileCache = new LRUCache\u003Cstring, UserProfile>({\n  max: 10_000,\n  ttl: 5 * 60 * 1000,\n  allowStale: true,\n  fetchMethod: async (userId) => db.users.findUnique({ where: { id: userId } }),\n});\n\nasync function getProfile(userId: string): Promise\u003CUserProfile> {\n  return profileCache.fetch(userId);\n}\n",[1637],{"type":43,"tag":281,"props":1638,"children":1639},{"__ignoreMap":411},[1640,1683,1690,1746,1768,1808,1830,1933,1948,1955,2010,2047],{"type":43,"tag":417,"props":1641,"children":1642},{"class":419,"line":30},[1643,1648,1652,1657,1661,1666,1670,1675,1679],{"type":43,"tag":417,"props":1644,"children":1645},{"style":625},[1646],{"type":49,"value":1647},"import",{"type":43,"tag":417,"props":1649,"children":1650},{"style":435},[1651],{"type":49,"value":1029},{"type":43,"tag":417,"props":1653,"children":1654},{"style":482},[1655],{"type":49,"value":1656}," LRUCache",{"type":43,"tag":417,"props":1658,"children":1659},{"style":435},[1660],{"type":49,"value":1048},{"type":43,"tag":417,"props":1662,"children":1663},{"style":625},[1664],{"type":49,"value":1665}," from",{"type":43,"tag":417,"props":1667,"children":1668},{"style":435},[1669],{"type":49,"value":1523},{"type":43,"tag":417,"props":1671,"children":1672},{"style":518},[1673],{"type":49,"value":1674},"lru-cache",{"type":43,"tag":417,"props":1676,"children":1677},{"style":435},[1678],{"type":49,"value":515},{"type":43,"tag":417,"props":1680,"children":1681},{"style":435},[1682],{"type":49,"value":619},{"type":43,"tag":417,"props":1684,"children":1685},{"class":419,"line":473},[1686],{"type":43,"tag":417,"props":1687,"children":1688},{"emptyLinePlaceholder":760},[1689],{"type":49,"value":763},{"type":43,"tag":417,"props":1691,"children":1692},{"class":419,"line":26},[1693,1697,1702,1706,1711,1715,1719,1724,1728,1733,1737,1741],{"type":43,"tag":417,"props":1694,"children":1695},{"style":423},[1696],{"type":49,"value":730},{"type":43,"tag":417,"props":1698,"children":1699},{"style":482},[1700],{"type":49,"value":1701}," profileCache ",{"type":43,"tag":417,"props":1703,"children":1704},{"style":435},[1705],{"type":49,"value":740},{"type":43,"tag":417,"props":1707,"children":1708},{"style":435},[1709],{"type":49,"value":1710}," new",{"type":43,"tag":417,"props":1712,"children":1713},{"style":429},[1714],{"type":49,"value":1656},{"type":43,"tag":417,"props":1716,"children":1717},{"style":435},[1718],{"type":49,"value":812},{"type":43,"tag":417,"props":1720,"children":1721},{"style":452},[1722],{"type":49,"value":1723},"string",{"type":43,"tag":417,"props":1725,"children":1726},{"style":435},[1727],{"type":49,"value":605},{"type":43,"tag":417,"props":1729,"children":1730},{"style":452},[1731],{"type":49,"value":1732}," UserProfile",{"type":43,"tag":417,"props":1734,"children":1735},{"style":435},[1736],{"type":49,"value":822},{"type":43,"tag":417,"props":1738,"children":1739},{"style":482},[1740],{"type":49,"value":438},{"type":43,"tag":417,"props":1742,"children":1743},{"style":435},[1744],{"type":49,"value":1745},"{\n",{"type":43,"tag":417,"props":1747,"children":1748},{"class":419,"line":677},[1749,1754,1758,1763],{"type":43,"tag":417,"props":1750,"children":1751},{"style":508},[1752],{"type":49,"value":1753},"  max",{"type":43,"tag":417,"props":1755,"children":1756},{"style":435},[1757],{"type":49,"value":449},{"type":43,"tag":417,"props":1759,"children":1760},{"style":597},[1761],{"type":49,"value":1762}," 10_000",{"type":43,"tag":417,"props":1764,"children":1765},{"style":435},[1766],{"type":49,"value":1767},",\n",{"type":43,"tag":417,"props":1769,"children":1770},{"class":419,"line":898},[1771,1776,1780,1785,1790,1795,1799,1804],{"type":43,"tag":417,"props":1772,"children":1773},{"style":508},[1774],{"type":49,"value":1775},"  ttl",{"type":43,"tag":417,"props":1777,"children":1778},{"style":435},[1779],{"type":49,"value":449},{"type":43,"tag":417,"props":1781,"children":1782},{"style":597},[1783],{"type":49,"value":1784}," 5",{"type":43,"tag":417,"props":1786,"children":1787},{"style":435},[1788],{"type":49,"value":1789}," *",{"type":43,"tag":417,"props":1791,"children":1792},{"style":597},[1793],{"type":49,"value":1794}," 60",{"type":43,"tag":417,"props":1796,"children":1797},{"style":435},[1798],{"type":49,"value":1789},{"type":43,"tag":417,"props":1800,"children":1801},{"style":597},[1802],{"type":49,"value":1803}," 1000",{"type":43,"tag":417,"props":1805,"children":1806},{"style":435},[1807],{"type":49,"value":1767},{"type":43,"tag":417,"props":1809,"children":1810},{"class":419,"line":957},[1811,1816,1820,1826],{"type":43,"tag":417,"props":1812,"children":1813},{"style":508},[1814],{"type":49,"value":1815},"  allowStale",{"type":43,"tag":417,"props":1817,"children":1818},{"style":435},[1819],{"type":49,"value":449},{"type":43,"tag":417,"props":1821,"children":1823},{"style":1822},"--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC",[1824],{"type":49,"value":1825}," true",{"type":43,"tag":417,"props":1827,"children":1828},{"style":435},[1829],{"type":49,"value":1767},{"type":43,"tag":417,"props":1831,"children":1832},{"class":419,"line":965},[1833,1838,1842,1847,1851,1855,1859,1864,1868,1872,1876,1880,1884,1888,1892,1896,1900,1904,1908,1912,1917,1921,1925,1929],{"type":43,"tag":417,"props":1834,"children":1835},{"style":429},[1836],{"type":49,"value":1837},"  fetchMethod",{"type":43,"tag":417,"props":1839,"children":1840},{"style":435},[1841],{"type":49,"value":449},{"type":43,"tag":417,"props":1843,"children":1844},{"style":423},[1845],{"type":49,"value":1846}," async",{"type":43,"tag":417,"props":1848,"children":1849},{"style":435},[1850],{"type":49,"value":909},{"type":43,"tag":417,"props":1852,"children":1853},{"style":441},[1854],{"type":49,"value":790},{"type":43,"tag":417,"props":1856,"children":1857},{"style":435},[1858],{"type":49,"value":530},{"type":43,"tag":417,"props":1860,"children":1861},{"style":423},[1862],{"type":49,"value":1863}," =>",{"type":43,"tag":417,"props":1865,"children":1866},{"style":482},[1867],{"type":49,"value":988},{"type":43,"tag":417,"props":1869,"children":1870},{"style":435},[1871],{"type":49,"value":500},{"type":43,"tag":417,"props":1873,"children":1874},{"style":482},[1875],{"type":49,"value":997},{"type":43,"tag":417,"props":1877,"children":1878},{"style":435},[1879],{"type":49,"value":500},{"type":43,"tag":417,"props":1881,"children":1882},{"style":429},[1883],{"type":49,"value":1006},{"type":43,"tag":417,"props":1885,"children":1886},{"style":482},[1887],{"type":49,"value":438},{"type":43,"tag":417,"props":1889,"children":1890},{"style":435},[1891],{"type":49,"value":1015},{"type":43,"tag":417,"props":1893,"children":1894},{"style":508},[1895],{"type":49,"value":1020},{"type":43,"tag":417,"props":1897,"children":1898},{"style":435},[1899],{"type":49,"value":449},{"type":43,"tag":417,"props":1901,"children":1902},{"style":435},[1903],{"type":49,"value":1029},{"type":43,"tag":417,"props":1905,"children":1906},{"style":508},[1907],{"type":49,"value":1034},{"type":43,"tag":417,"props":1909,"children":1910},{"style":435},[1911],{"type":49,"value":449},{"type":43,"tag":417,"props":1913,"children":1914},{"style":482},[1915],{"type":49,"value":1916}," userId ",{"type":43,"tag":417,"props":1918,"children":1919},{"style":435},[1920],{"type":49,"value":653},{"type":43,"tag":417,"props":1922,"children":1923},{"style":435},[1924],{"type":49,"value":1048},{"type":43,"tag":417,"props":1926,"children":1927},{"style":482},[1928],{"type":49,"value":530},{"type":43,"tag":417,"props":1930,"children":1931},{"style":435},[1932],{"type":49,"value":1767},{"type":43,"tag":417,"props":1934,"children":1935},{"class":419,"line":1063},[1936,1940,1944],{"type":43,"tag":417,"props":1937,"children":1938},{"style":435},[1939],{"type":49,"value":653},{"type":43,"tag":417,"props":1941,"children":1942},{"style":482},[1943],{"type":49,"value":530},{"type":43,"tag":417,"props":1945,"children":1946},{"style":435},[1947],{"type":49,"value":619},{"type":43,"tag":417,"props":1949,"children":1950},{"class":419,"line":1153},[1951],{"type":43,"tag":417,"props":1952,"children":1953},{"emptyLinePlaceholder":760},[1954],{"type":49,"value":763},{"type":43,"tag":417,"props":1956,"children":1957},{"class":419,"line":1169},[1958,1962,1966,1970,1974,1978,1982,1986,1990,1994,1998,2002,2006],{"type":43,"tag":417,"props":1959,"children":1960},{"style":423},[1961],{"type":49,"value":771},{"type":43,"tag":417,"props":1963,"children":1964},{"style":423},[1965],{"type":49,"value":776},{"type":43,"tag":417,"props":1967,"children":1968},{"style":429},[1969],{"type":49,"value":781},{"type":43,"tag":417,"props":1971,"children":1972},{"style":435},[1973],{"type":49,"value":438},{"type":43,"tag":417,"props":1975,"children":1976},{"style":441},[1977],{"type":49,"value":790},{"type":43,"tag":417,"props":1979,"children":1980},{"style":435},[1981],{"type":49,"value":449},{"type":43,"tag":417,"props":1983,"children":1984},{"style":452},[1985],{"type":49,"value":465},{"type":43,"tag":417,"props":1987,"children":1988},{"style":435},[1989],{"type":49,"value":460},{"type":43,"tag":417,"props":1991,"children":1992},{"style":452},[1993],{"type":49,"value":807},{"type":43,"tag":417,"props":1995,"children":1996},{"style":435},[1997],{"type":49,"value":812},{"type":43,"tag":417,"props":1999,"children":2000},{"style":452},[2001],{"type":49,"value":817},{"type":43,"tag":417,"props":2003,"children":2004},{"style":435},[2005],{"type":49,"value":822},{"type":43,"tag":417,"props":2007,"children":2008},{"style":435},[2009],{"type":49,"value":470},{"type":43,"tag":417,"props":2011,"children":2012},{"class":419,"line":1177},[2013,2017,2022,2026,2031,2035,2039,2043],{"type":43,"tag":417,"props":2014,"children":2015},{"style":625},[2016],{"type":49,"value":628},{"type":43,"tag":417,"props":2018,"children":2019},{"style":482},[2020],{"type":49,"value":2021}," profileCache",{"type":43,"tag":417,"props":2023,"children":2024},{"style":435},[2025],{"type":49,"value":500},{"type":43,"tag":417,"props":2027,"children":2028},{"style":429},[2029],{"type":49,"value":2030},"fetch",{"type":43,"tag":417,"props":2032,"children":2033},{"style":508},[2034],{"type":49,"value":438},{"type":43,"tag":417,"props":2036,"children":2037},{"style":482},[2038],{"type":49,"value":790},{"type":43,"tag":417,"props":2040,"children":2041},{"style":508},[2042],{"type":49,"value":530},{"type":43,"tag":417,"props":2044,"children":2045},{"style":435},[2046],{"type":49,"value":619},{"type":43,"tag":417,"props":2048,"children":2049},{"class":419,"line":1185},[2050],{"type":43,"tag":417,"props":2051,"children":2052},{"style":435},[2053],{"type":49,"value":683},{"type":43,"tag":394,"props":2055,"children":2057},{"id":2056},"cache-stampede-prevention-single-flight",[2058],{"type":49,"value":2059},"Cache stampede prevention (single-flight)",{"type":43,"tag":52,"props":2061,"children":2062},{},[2063],{"type":49,"value":2064},"When a popular entry expires, hundreds of requests see a miss simultaneously and all hit the database. Coalesce them into one.",{"type":43,"tag":406,"props":2066,"children":2068},{"className":408,"code":2067,"language":410,"meta":411,"style":411},"const inFlight = new Map\u003Cstring, Promise\u003Cany>>();\n\nasync function getCached\u003CT>(key: string, fetcher: () => Promise\u003CT>, ttlSeconds: number): Promise\u003CT> {\n  const cached = await redis.get(key);\n  if (cached) return JSON.parse(cached);\n  if (inFlight.has(key)) return inFlight.get(key) as Promise\u003CT>; \u002F\u002F already fetching, wait for it\n\n  const promise = fetcher()\n    .then(async (result) => {\n      await redis.setex(key, ttlSeconds, JSON.stringify(result));\n      inFlight.delete(key);\n      return result;\n    })\n    .catch((err) => {\n      inFlight.delete(key);\n      throw err;\n    });\n\n  inFlight.set(key, promise);\n  return promise;\n}\n",[2069],{"type":43,"tag":281,"props":2070,"children":2071},{"__ignoreMap":411},[2072,2136,2143,2263,2310,2361,2455,2462,2487,2529,2597,2629,2646,2659,2696,2727,2744,2759,2766,2808,2824],{"type":43,"tag":417,"props":2073,"children":2074},{"class":419,"line":30},[2075,2079,2084,2088,2092,2097,2101,2105,2109,2113,2117,2122,2127,2132],{"type":43,"tag":417,"props":2076,"children":2077},{"style":423},[2078],{"type":49,"value":730},{"type":43,"tag":417,"props":2080,"children":2081},{"style":482},[2082],{"type":49,"value":2083}," inFlight ",{"type":43,"tag":417,"props":2085,"children":2086},{"style":435},[2087],{"type":49,"value":740},{"type":43,"tag":417,"props":2089,"children":2090},{"style":435},[2091],{"type":49,"value":1710},{"type":43,"tag":417,"props":2093,"children":2094},{"style":429},[2095],{"type":49,"value":2096}," Map",{"type":43,"tag":417,"props":2098,"children":2099},{"style":435},[2100],{"type":49,"value":812},{"type":43,"tag":417,"props":2102,"children":2103},{"style":452},[2104],{"type":49,"value":1723},{"type":43,"tag":417,"props":2106,"children":2107},{"style":435},[2108],{"type":49,"value":605},{"type":43,"tag":417,"props":2110,"children":2111},{"style":452},[2112],{"type":49,"value":807},{"type":43,"tag":417,"props":2114,"children":2115},{"style":435},[2116],{"type":49,"value":812},{"type":43,"tag":417,"props":2118,"children":2119},{"style":452},[2120],{"type":49,"value":2121},"any",{"type":43,"tag":417,"props":2123,"children":2124},{"style":435},[2125],{"type":49,"value":2126},">>",{"type":43,"tag":417,"props":2128,"children":2129},{"style":482},[2130],{"type":49,"value":2131},"()",{"type":43,"tag":417,"props":2133,"children":2134},{"style":435},[2135],{"type":49,"value":619},{"type":43,"tag":417,"props":2137,"children":2138},{"class":419,"line":473},[2139],{"type":43,"tag":417,"props":2140,"children":2141},{"emptyLinePlaceholder":760},[2142],{"type":49,"value":763},{"type":43,"tag":417,"props":2144,"children":2145},{"class":419,"line":26},[2146,2150,2154,2159,2163,2168,2173,2178,2182,2186,2190,2195,2199,2204,2208,2212,2216,2220,2225,2230,2234,2239,2243,2247,2251,2255,2259],{"type":43,"tag":417,"props":2147,"children":2148},{"style":423},[2149],{"type":49,"value":771},{"type":43,"tag":417,"props":2151,"children":2152},{"style":423},[2153],{"type":49,"value":776},{"type":43,"tag":417,"props":2155,"children":2156},{"style":429},[2157],{"type":49,"value":2158}," getCached",{"type":43,"tag":417,"props":2160,"children":2161},{"style":435},[2162],{"type":49,"value":812},{"type":43,"tag":417,"props":2164,"children":2165},{"style":452},[2166],{"type":49,"value":2167},"T",{"type":43,"tag":417,"props":2169,"children":2170},{"style":435},[2171],{"type":49,"value":2172},">(",{"type":43,"tag":417,"props":2174,"children":2175},{"style":441},[2176],{"type":49,"value":2177},"key",{"type":43,"tag":417,"props":2179,"children":2180},{"style":435},[2181],{"type":49,"value":449},{"type":43,"tag":417,"props":2183,"children":2184},{"style":452},[2185],{"type":49,"value":465},{"type":43,"tag":417,"props":2187,"children":2188},{"style":435},[2189],{"type":49,"value":605},{"type":43,"tag":417,"props":2191,"children":2192},{"style":429},[2193],{"type":49,"value":2194}," fetcher",{"type":43,"tag":417,"props":2196,"children":2197},{"style":435},[2198],{"type":49,"value":449},{"type":43,"tag":417,"props":2200,"children":2201},{"style":435},[2202],{"type":49,"value":2203}," ()",{"type":43,"tag":417,"props":2205,"children":2206},{"style":423},[2207],{"type":49,"value":1863},{"type":43,"tag":417,"props":2209,"children":2210},{"style":452},[2211],{"type":49,"value":807},{"type":43,"tag":417,"props":2213,"children":2214},{"style":435},[2215],{"type":49,"value":812},{"type":43,"tag":417,"props":2217,"children":2218},{"style":452},[2219],{"type":49,"value":2167},{"type":43,"tag":417,"props":2221,"children":2222},{"style":435},[2223],{"type":49,"value":2224},">,",{"type":43,"tag":417,"props":2226,"children":2227},{"style":441},[2228],{"type":49,"value":2229}," ttlSeconds",{"type":43,"tag":417,"props":2231,"children":2232},{"style":435},[2233],{"type":49,"value":449},{"type":43,"tag":417,"props":2235,"children":2236},{"style":452},[2237],{"type":49,"value":2238}," number",{"type":43,"tag":417,"props":2240,"children":2241},{"style":435},[2242],{"type":49,"value":460},{"type":43,"tag":417,"props":2244,"children":2245},{"style":452},[2246],{"type":49,"value":807},{"type":43,"tag":417,"props":2248,"children":2249},{"style":435},[2250],{"type":49,"value":812},{"type":43,"tag":417,"props":2252,"children":2253},{"style":452},[2254],{"type":49,"value":2167},{"type":43,"tag":417,"props":2256,"children":2257},{"style":435},[2258],{"type":49,"value":822},{"type":43,"tag":417,"props":2260,"children":2261},{"style":435},[2262],{"type":49,"value":470},{"type":43,"tag":417,"props":2264,"children":2265},{"class":419,"line":677},[2266,2270,2274,2278,2282,2286,2290,2294,2298,2302,2306],{"type":43,"tag":417,"props":2267,"children":2268},{"style":423},[2269],{"type":49,"value":479},{"type":43,"tag":417,"props":2271,"children":2272},{"style":482},[2273],{"type":49,"value":838},{"type":43,"tag":417,"props":2275,"children":2276},{"style":435},[2277],{"type":49,"value":490},{"type":43,"tag":417,"props":2279,"children":2280},{"style":625},[2281],{"type":49,"value":847},{"type":43,"tag":417,"props":2283,"children":2284},{"style":482},[2285],{"type":49,"value":852},{"type":43,"tag":417,"props":2287,"children":2288},{"style":435},[2289],{"type":49,"value":500},{"type":43,"tag":417,"props":2291,"children":2292},{"style":429},[2293],{"type":49,"value":861},{"type":43,"tag":417,"props":2295,"children":2296},{"style":508},[2297],{"type":49,"value":438},{"type":43,"tag":417,"props":2299,"children":2300},{"style":482},[2301],{"type":49,"value":2177},{"type":43,"tag":417,"props":2303,"children":2304},{"style":508},[2305],{"type":49,"value":530},{"type":43,"tag":417,"props":2307,"children":2308},{"style":435},[2309],{"type":49,"value":619},{"type":43,"tag":417,"props":2311,"children":2312},{"class":419,"line":898},[2313,2317,2321,2325,2329,2333,2337,2341,2345,2349,2353,2357],{"type":43,"tag":417,"props":2314,"children":2315},{"style":625},[2316],{"type":49,"value":904},{"type":43,"tag":417,"props":2318,"children":2319},{"style":508},[2320],{"type":49,"value":909},{"type":43,"tag":417,"props":2322,"children":2323},{"style":482},[2324],{"type":49,"value":914},{"type":43,"tag":417,"props":2326,"children":2327},{"style":508},[2328],{"type":49,"value":919},{"type":43,"tag":417,"props":2330,"children":2331},{"style":625},[2332],{"type":49,"value":924},{"type":43,"tag":417,"props":2334,"children":2335},{"style":482},[2336],{"type":49,"value":929},{"type":43,"tag":417,"props":2338,"children":2339},{"style":435},[2340],{"type":49,"value":500},{"type":43,"tag":417,"props":2342,"children":2343},{"style":429},[2344],{"type":49,"value":938},{"type":43,"tag":417,"props":2346,"children":2347},{"style":508},[2348],{"type":49,"value":438},{"type":43,"tag":417,"props":2350,"children":2351},{"style":482},[2352],{"type":49,"value":914},{"type":43,"tag":417,"props":2354,"children":2355},{"style":508},[2356],{"type":49,"value":530},{"type":43,"tag":417,"props":2358,"children":2359},{"style":435},[2360],{"type":49,"value":619},{"type":43,"tag":417,"props":2362,"children":2363},{"class":419,"line":957},[2364,2368,2372,2377,2381,2386,2390,2394,2399,2403,2408,2412,2416,2420,2424,2428,2433,2437,2441,2445,2450],{"type":43,"tag":417,"props":2365,"children":2366},{"style":625},[2367],{"type":49,"value":904},{"type":43,"tag":417,"props":2369,"children":2370},{"style":508},[2371],{"type":49,"value":909},{"type":43,"tag":417,"props":2373,"children":2374},{"style":482},[2375],{"type":49,"value":2376},"inFlight",{"type":43,"tag":417,"props":2378,"children":2379},{"style":435},[2380],{"type":49,"value":500},{"type":43,"tag":417,"props":2382,"children":2383},{"style":429},[2384],{"type":49,"value":2385},"has",{"type":43,"tag":417,"props":2387,"children":2388},{"style":508},[2389],{"type":49,"value":438},{"type":43,"tag":417,"props":2391,"children":2392},{"style":482},[2393],{"type":49,"value":2177},{"type":43,"tag":417,"props":2395,"children":2396},{"style":508},[2397],{"type":49,"value":2398},")) ",{"type":43,"tag":417,"props":2400,"children":2401},{"style":625},[2402],{"type":49,"value":924},{"type":43,"tag":417,"props":2404,"children":2405},{"style":482},[2406],{"type":49,"value":2407}," inFlight",{"type":43,"tag":417,"props":2409,"children":2410},{"style":435},[2411],{"type":49,"value":500},{"type":43,"tag":417,"props":2413,"children":2414},{"style":429},[2415],{"type":49,"value":861},{"type":43,"tag":417,"props":2417,"children":2418},{"style":508},[2419],{"type":49,"value":438},{"type":43,"tag":417,"props":2421,"children":2422},{"style":482},[2423],{"type":49,"value":2177},{"type":43,"tag":417,"props":2425,"children":2426},{"style":508},[2427],{"type":49,"value":919},{"type":43,"tag":417,"props":2429,"children":2430},{"style":625},[2431],{"type":49,"value":2432},"as",{"type":43,"tag":417,"props":2434,"children":2435},{"style":452},[2436],{"type":49,"value":807},{"type":43,"tag":417,"props":2438,"children":2439},{"style":435},[2440],{"type":49,"value":812},{"type":43,"tag":417,"props":2442,"children":2443},{"style":452},[2444],{"type":49,"value":2167},{"type":43,"tag":417,"props":2446,"children":2447},{"style":435},[2448],{"type":49,"value":2449},">;",{"type":43,"tag":417,"props":2451,"children":2452},{"style":671},[2453],{"type":49,"value":2454}," \u002F\u002F already fetching, wait for it\n",{"type":43,"tag":417,"props":2456,"children":2457},{"class":419,"line":965},[2458],{"type":43,"tag":417,"props":2459,"children":2460},{"emptyLinePlaceholder":760},[2461],{"type":49,"value":763},{"type":43,"tag":417,"props":2463,"children":2464},{"class":419,"line":1063},[2465,2469,2474,2478,2482],{"type":43,"tag":417,"props":2466,"children":2467},{"style":423},[2468],{"type":49,"value":479},{"type":43,"tag":417,"props":2470,"children":2471},{"style":482},[2472],{"type":49,"value":2473}," promise",{"type":43,"tag":417,"props":2475,"children":2476},{"style":435},[2477],{"type":49,"value":490},{"type":43,"tag":417,"props":2479,"children":2480},{"style":429},[2481],{"type":49,"value":2194},{"type":43,"tag":417,"props":2483,"children":2484},{"style":508},[2485],{"type":49,"value":2486},"()\n",{"type":43,"tag":417,"props":2488,"children":2489},{"class":419,"line":1153},[2490,2495,2500,2504,2508,2512,2517,2521,2525],{"type":43,"tag":417,"props":2491,"children":2492},{"style":435},[2493],{"type":49,"value":2494},"    .",{"type":43,"tag":417,"props":2496,"children":2497},{"style":429},[2498],{"type":49,"value":2499},"then",{"type":43,"tag":417,"props":2501,"children":2502},{"style":508},[2503],{"type":49,"value":438},{"type":43,"tag":417,"props":2505,"children":2506},{"style":423},[2507],{"type":49,"value":771},{"type":43,"tag":417,"props":2509,"children":2510},{"style":435},[2511],{"type":49,"value":909},{"type":43,"tag":417,"props":2513,"children":2514},{"style":441},[2515],{"type":49,"value":2516},"result",{"type":43,"tag":417,"props":2518,"children":2519},{"style":435},[2520],{"type":49,"value":530},{"type":43,"tag":417,"props":2522,"children":2523},{"style":423},[2524],{"type":49,"value":1863},{"type":43,"tag":417,"props":2526,"children":2527},{"style":435},[2528],{"type":49,"value":470},{"type":43,"tag":417,"props":2530,"children":2531},{"class":419,"line":1169},[2532,2537,2541,2545,2549,2553,2557,2561,2565,2569,2573,2577,2581,2585,2589,2593],{"type":43,"tag":417,"props":2533,"children":2534},{"style":625},[2535],{"type":49,"value":2536},"      await",{"type":43,"tag":417,"props":2538,"children":2539},{"style":482},[2540],{"type":49,"value":852},{"type":43,"tag":417,"props":2542,"children":2543},{"style":435},[2544],{"type":49,"value":500},{"type":43,"tag":417,"props":2546,"children":2547},{"style":429},[2548],{"type":49,"value":1082},{"type":43,"tag":417,"props":2550,"children":2551},{"style":508},[2552],{"type":49,"value":438},{"type":43,"tag":417,"props":2554,"children":2555},{"style":482},[2556],{"type":49,"value":2177},{"type":43,"tag":417,"props":2558,"children":2559},{"style":435},[2560],{"type":49,"value":605},{"type":43,"tag":417,"props":2562,"children":2563},{"style":482},[2564],{"type":49,"value":2229},{"type":43,"tag":417,"props":2566,"children":2567},{"style":435},[2568],{"type":49,"value":605},{"type":43,"tag":417,"props":2570,"children":2571},{"style":482},[2572],{"type":49,"value":929},{"type":43,"tag":417,"props":2574,"children":2575},{"style":435},[2576],{"type":49,"value":500},{"type":43,"tag":417,"props":2578,"children":2579},{"style":429},[2580],{"type":49,"value":1132},{"type":43,"tag":417,"props":2582,"children":2583},{"style":508},[2584],{"type":49,"value":438},{"type":43,"tag":417,"props":2586,"children":2587},{"style":482},[2588],{"type":49,"value":2516},{"type":43,"tag":417,"props":2590,"children":2591},{"style":508},[2592],{"type":49,"value":1146},{"type":43,"tag":417,"props":2594,"children":2595},{"style":435},[2596],{"type":49,"value":619},{"type":43,"tag":417,"props":2598,"children":2599},{"class":419,"line":1177},[2600,2605,2609,2613,2617,2621,2625],{"type":43,"tag":417,"props":2601,"children":2602},{"style":482},[2603],{"type":49,"value":2604},"      inFlight",{"type":43,"tag":417,"props":2606,"children":2607},{"style":435},[2608],{"type":49,"value":500},{"type":43,"tag":417,"props":2610,"children":2611},{"style":429},[2612],{"type":49,"value":1586},{"type":43,"tag":417,"props":2614,"children":2615},{"style":508},[2616],{"type":49,"value":438},{"type":43,"tag":417,"props":2618,"children":2619},{"style":482},[2620],{"type":49,"value":2177},{"type":43,"tag":417,"props":2622,"children":2623},{"style":508},[2624],{"type":49,"value":530},{"type":43,"tag":417,"props":2626,"children":2627},{"style":435},[2628],{"type":49,"value":619},{"type":43,"tag":417,"props":2630,"children":2631},{"class":419,"line":1185},[2632,2637,2642],{"type":43,"tag":417,"props":2633,"children":2634},{"style":625},[2635],{"type":49,"value":2636},"      return",{"type":43,"tag":417,"props":2638,"children":2639},{"style":482},[2640],{"type":49,"value":2641}," result",{"type":43,"tag":417,"props":2643,"children":2644},{"style":435},[2645],{"type":49,"value":619},{"type":43,"tag":417,"props":2647,"children":2648},{"class":419,"line":1253},[2649,2654],{"type":43,"tag":417,"props":2650,"children":2651},{"style":435},[2652],{"type":49,"value":2653},"    }",{"type":43,"tag":417,"props":2655,"children":2656},{"style":508},[2657],{"type":49,"value":2658},")\n",{"type":43,"tag":417,"props":2660,"children":2661},{"class":419,"line":1347},[2662,2666,2671,2675,2679,2684,2688,2692],{"type":43,"tag":417,"props":2663,"children":2664},{"style":435},[2665],{"type":49,"value":2494},{"type":43,"tag":417,"props":2667,"children":2668},{"style":429},[2669],{"type":49,"value":2670},"catch",{"type":43,"tag":417,"props":2672,"children":2673},{"style":508},[2674],{"type":49,"value":438},{"type":43,"tag":417,"props":2676,"children":2677},{"style":435},[2678],{"type":49,"value":438},{"type":43,"tag":417,"props":2680,"children":2681},{"style":441},[2682],{"type":49,"value":2683},"err",{"type":43,"tag":417,"props":2685,"children":2686},{"style":435},[2687],{"type":49,"value":530},{"type":43,"tag":417,"props":2689,"children":2690},{"style":423},[2691],{"type":49,"value":1863},{"type":43,"tag":417,"props":2693,"children":2694},{"style":435},[2695],{"type":49,"value":470},{"type":43,"tag":417,"props":2697,"children":2698},{"class":419,"line":1356},[2699,2703,2707,2711,2715,2719,2723],{"type":43,"tag":417,"props":2700,"children":2701},{"style":482},[2702],{"type":49,"value":2604},{"type":43,"tag":417,"props":2704,"children":2705},{"style":435},[2706],{"type":49,"value":500},{"type":43,"tag":417,"props":2708,"children":2709},{"style":429},[2710],{"type":49,"value":1586},{"type":43,"tag":417,"props":2712,"children":2713},{"style":508},[2714],{"type":49,"value":438},{"type":43,"tag":417,"props":2716,"children":2717},{"style":482},[2718],{"type":49,"value":2177},{"type":43,"tag":417,"props":2720,"children":2721},{"style":508},[2722],{"type":49,"value":530},{"type":43,"tag":417,"props":2724,"children":2725},{"style":435},[2726],{"type":49,"value":619},{"type":43,"tag":417,"props":2728,"children":2729},{"class":419,"line":1441},[2730,2735,2740],{"type":43,"tag":417,"props":2731,"children":2732},{"style":625},[2733],{"type":49,"value":2734},"      throw",{"type":43,"tag":417,"props":2736,"children":2737},{"style":482},[2738],{"type":49,"value":2739}," err",{"type":43,"tag":417,"props":2741,"children":2742},{"style":435},[2743],{"type":49,"value":619},{"type":43,"tag":417,"props":2745,"children":2746},{"class":419,"line":1450},[2747,2751,2755],{"type":43,"tag":417,"props":2748,"children":2749},{"style":435},[2750],{"type":49,"value":2653},{"type":43,"tag":417,"props":2752,"children":2753},{"style":508},[2754],{"type":49,"value":530},{"type":43,"tag":417,"props":2756,"children":2757},{"style":435},[2758],{"type":49,"value":619},{"type":43,"tag":417,"props":2760,"children":2761},{"class":419,"line":1562},[2762],{"type":43,"tag":417,"props":2763,"children":2764},{"emptyLinePlaceholder":760},[2765],{"type":49,"value":763},{"type":43,"tag":417,"props":2767,"children":2769},{"class":419,"line":2768},19,[2770,2775,2779,2784,2788,2792,2796,2800,2804],{"type":43,"tag":417,"props":2771,"children":2772},{"style":482},[2773],{"type":49,"value":2774},"  inFlight",{"type":43,"tag":417,"props":2776,"children":2777},{"style":435},[2778],{"type":49,"value":500},{"type":43,"tag":417,"props":2780,"children":2781},{"style":429},[2782],{"type":49,"value":2783},"set",{"type":43,"tag":417,"props":2785,"children":2786},{"style":508},[2787],{"type":49,"value":438},{"type":43,"tag":417,"props":2789,"children":2790},{"style":482},[2791],{"type":49,"value":2177},{"type":43,"tag":417,"props":2793,"children":2794},{"style":435},[2795],{"type":49,"value":605},{"type":43,"tag":417,"props":2797,"children":2798},{"style":482},[2799],{"type":49,"value":2473},{"type":43,"tag":417,"props":2801,"children":2802},{"style":508},[2803],{"type":49,"value":530},{"type":43,"tag":417,"props":2805,"children":2806},{"style":435},[2807],{"type":49,"value":619},{"type":43,"tag":417,"props":2809,"children":2811},{"class":419,"line":2810},20,[2812,2816,2820],{"type":43,"tag":417,"props":2813,"children":2814},{"style":625},[2815],{"type":49,"value":628},{"type":43,"tag":417,"props":2817,"children":2818},{"style":482},[2819],{"type":49,"value":2473},{"type":43,"tag":417,"props":2821,"children":2822},{"style":435},[2823],{"type":49,"value":619},{"type":43,"tag":417,"props":2825,"children":2827},{"class":419,"line":2826},21,[2828],{"type":43,"tag":417,"props":2829,"children":2830},{"style":435},[2831],{"type":49,"value":683},{"type":43,"tag":52,"props":2833,"children":2834},{},[2835],{"type":49,"value":2836},"This works within a single process only. For multi-instance stampede prevention, use a distributed lock or probabilistic early expiration (each request has a small random chance of refreshing before TTL).",{"type":43,"tag":394,"props":2838,"children":2840},{"id":2839},"cache-key-design",[2841],{"type":49,"value":2842},"Cache key design",{"type":43,"tag":52,"props":2844,"children":2845},{},[2846],{"type":49,"value":2847},"Every variable that affects the cached value must be in the key, or different contexts share data they shouldn't.",{"type":43,"tag":406,"props":2849,"children":2851},{"className":408,"code":2850,"language":410,"meta":411,"style":411},"const key = `product:${productId}`;                                  \u002F\u002F BAD: ignores locale\u002Fcurrency\nconst key = `product:${productId}:locale:${locale}:currency:${currency}`;\nconst key = `dashboard:${userId}:${orgId}`;                          \u002F\u002F user-specific data\nconst key = `orders:${userId}:page:${page}:size:${pageSize}:sort:${sortBy}`; \u002F\u002F paginated data\n",[2852],{"type":43,"tag":281,"props":2853,"children":2854},{"__ignoreMap":411},[2855,2902,2977,3039],{"type":43,"tag":417,"props":2856,"children":2857},{"class":419,"line":30},[2858,2862,2867,2871,2875,2880,2884,2889,2893,2897],{"type":43,"tag":417,"props":2859,"children":2860},{"style":423},[2861],{"type":49,"value":730},{"type":43,"tag":417,"props":2863,"children":2864},{"style":482},[2865],{"type":49,"value":2866}," key ",{"type":43,"tag":417,"props":2868,"children":2869},{"style":435},[2870],{"type":49,"value":740},{"type":43,"tag":417,"props":2872,"children":2873},{"style":435},[2874],{"type":49,"value":633},{"type":43,"tag":417,"props":2876,"children":2877},{"style":518},[2878],{"type":49,"value":2879},"product:",{"type":43,"tag":417,"props":2881,"children":2882},{"style":435},[2883],{"type":49,"value":643},{"type":43,"tag":417,"props":2885,"children":2886},{"style":482},[2887],{"type":49,"value":2888},"productId",{"type":43,"tag":417,"props":2890,"children":2891},{"style":435},[2892],{"type":49,"value":887},{"type":43,"tag":417,"props":2894,"children":2895},{"style":435},[2896],{"type":49,"value":668},{"type":43,"tag":417,"props":2898,"children":2899},{"style":671},[2900],{"type":49,"value":2901},"                                  \u002F\u002F BAD: ignores locale\u002Fcurrency\n",{"type":43,"tag":417,"props":2903,"children":2904},{"class":419,"line":473},[2905,2909,2913,2917,2921,2925,2929,2933,2937,2942,2946,2951,2955,2960,2964,2969,2973],{"type":43,"tag":417,"props":2906,"children":2907},{"style":423},[2908],{"type":49,"value":730},{"type":43,"tag":417,"props":2910,"children":2911},{"style":482},[2912],{"type":49,"value":2866},{"type":43,"tag":417,"props":2914,"children":2915},{"style":435},[2916],{"type":49,"value":740},{"type":43,"tag":417,"props":2918,"children":2919},{"style":435},[2920],{"type":49,"value":633},{"type":43,"tag":417,"props":2922,"children":2923},{"style":518},[2924],{"type":49,"value":2879},{"type":43,"tag":417,"props":2926,"children":2927},{"style":435},[2928],{"type":49,"value":643},{"type":43,"tag":417,"props":2930,"children":2931},{"style":482},[2932],{"type":49,"value":2888},{"type":43,"tag":417,"props":2934,"children":2935},{"style":435},[2936],{"type":49,"value":653},{"type":43,"tag":417,"props":2938,"children":2939},{"style":518},[2940],{"type":49,"value":2941},":locale:",{"type":43,"tag":417,"props":2943,"children":2944},{"style":435},[2945],{"type":49,"value":643},{"type":43,"tag":417,"props":2947,"children":2948},{"style":482},[2949],{"type":49,"value":2950},"locale",{"type":43,"tag":417,"props":2952,"children":2953},{"style":435},[2954],{"type":49,"value":653},{"type":43,"tag":417,"props":2956,"children":2957},{"style":518},[2958],{"type":49,"value":2959},":currency:",{"type":43,"tag":417,"props":2961,"children":2962},{"style":435},[2963],{"type":49,"value":643},{"type":43,"tag":417,"props":2965,"children":2966},{"style":482},[2967],{"type":49,"value":2968},"currency",{"type":43,"tag":417,"props":2970,"children":2971},{"style":435},[2972],{"type":49,"value":887},{"type":43,"tag":417,"props":2974,"children":2975},{"style":435},[2976],{"type":49,"value":619},{"type":43,"tag":417,"props":2978,"children":2979},{"class":419,"line":26},[2980,2984,2988,2992,2996,3001,3005,3009,3013,3017,3021,3026,3030,3034],{"type":43,"tag":417,"props":2981,"children":2982},{"style":423},[2983],{"type":49,"value":730},{"type":43,"tag":417,"props":2985,"children":2986},{"style":482},[2987],{"type":49,"value":2866},{"type":43,"tag":417,"props":2989,"children":2990},{"style":435},[2991],{"type":49,"value":740},{"type":43,"tag":417,"props":2993,"children":2994},{"style":435},[2995],{"type":49,"value":633},{"type":43,"tag":417,"props":2997,"children":2998},{"style":518},[2999],{"type":49,"value":3000},"dashboard:",{"type":43,"tag":417,"props":3002,"children":3003},{"style":435},[3004],{"type":49,"value":643},{"type":43,"tag":417,"props":3006,"children":3007},{"style":482},[3008],{"type":49,"value":790},{"type":43,"tag":417,"props":3010,"children":3011},{"style":435},[3012],{"type":49,"value":653},{"type":43,"tag":417,"props":3014,"children":3015},{"style":518},[3016],{"type":49,"value":449},{"type":43,"tag":417,"props":3018,"children":3019},{"style":435},[3020],{"type":49,"value":643},{"type":43,"tag":417,"props":3022,"children":3023},{"style":482},[3024],{"type":49,"value":3025},"orgId",{"type":43,"tag":417,"props":3027,"children":3028},{"style":435},[3029],{"type":49,"value":887},{"type":43,"tag":417,"props":3031,"children":3032},{"style":435},[3033],{"type":49,"value":668},{"type":43,"tag":417,"props":3035,"children":3036},{"style":671},[3037],{"type":49,"value":3038},"                          \u002F\u002F user-specific data\n",{"type":43,"tag":417,"props":3040,"children":3041},{"class":419,"line":677},[3042,3046,3050,3054,3058,3063,3067,3071,3075,3080,3084,3089,3093,3098,3102,3107,3111,3116,3120,3125,3129,3133],{"type":43,"tag":417,"props":3043,"children":3044},{"style":423},[3045],{"type":49,"value":730},{"type":43,"tag":417,"props":3047,"children":3048},{"style":482},[3049],{"type":49,"value":2866},{"type":43,"tag":417,"props":3051,"children":3052},{"style":435},[3053],{"type":49,"value":740},{"type":43,"tag":417,"props":3055,"children":3056},{"style":435},[3057],{"type":49,"value":633},{"type":43,"tag":417,"props":3059,"children":3060},{"style":518},[3061],{"type":49,"value":3062},"orders:",{"type":43,"tag":417,"props":3064,"children":3065},{"style":435},[3066],{"type":49,"value":643},{"type":43,"tag":417,"props":3068,"children":3069},{"style":482},[3070],{"type":49,"value":790},{"type":43,"tag":417,"props":3072,"children":3073},{"style":435},[3074],{"type":49,"value":653},{"type":43,"tag":417,"props":3076,"children":3077},{"style":518},[3078],{"type":49,"value":3079},":page:",{"type":43,"tag":417,"props":3081,"children":3082},{"style":435},[3083],{"type":49,"value":643},{"type":43,"tag":417,"props":3085,"children":3086},{"style":482},[3087],{"type":49,"value":3088},"page",{"type":43,"tag":417,"props":3090,"children":3091},{"style":435},[3092],{"type":49,"value":653},{"type":43,"tag":417,"props":3094,"children":3095},{"style":518},[3096],{"type":49,"value":3097},":size:",{"type":43,"tag":417,"props":3099,"children":3100},{"style":435},[3101],{"type":49,"value":643},{"type":43,"tag":417,"props":3103,"children":3104},{"style":482},[3105],{"type":49,"value":3106},"pageSize",{"type":43,"tag":417,"props":3108,"children":3109},{"style":435},[3110],{"type":49,"value":653},{"type":43,"tag":417,"props":3112,"children":3113},{"style":518},[3114],{"type":49,"value":3115},":sort:",{"type":43,"tag":417,"props":3117,"children":3118},{"style":435},[3119],{"type":49,"value":643},{"type":43,"tag":417,"props":3121,"children":3122},{"style":482},[3123],{"type":49,"value":3124},"sortBy",{"type":43,"tag":417,"props":3126,"children":3127},{"style":435},[3128],{"type":49,"value":887},{"type":43,"tag":417,"props":3130,"children":3131},{"style":435},[3132],{"type":49,"value":668},{"type":43,"tag":417,"props":3134,"children":3135},{"style":671},[3136],{"type":49,"value":3137}," \u002F\u002F paginated data\n",{"type":43,"tag":64,"props":3139,"children":3141},{"id":3140},"what-to-cache-where",[3142],{"type":49,"value":3143},"What to Cache Where",{"type":43,"tag":87,"props":3145,"children":3146},{},[3147,3173],{"type":43,"tag":91,"props":3148,"children":3149},{},[3150],{"type":43,"tag":95,"props":3151,"children":3152},{},[3153,3158,3163,3168],{"type":43,"tag":99,"props":3154,"children":3155},{},[3156],{"type":49,"value":3157},"Data",{"type":43,"tag":99,"props":3159,"children":3160},{},[3161],{"type":49,"value":3162},"Invalidation strategy",{"type":43,"tag":99,"props":3164,"children":3165},{},[3166],{"type":49,"value":3167},"TTL",{"type":43,"tag":99,"props":3169,"children":3170},{},[3171],{"type":49,"value":3172},"Notes",{"type":43,"tag":120,"props":3174,"children":3175},{},[3176,3199,3222,3245,3268,3290,3313,3335],{"type":43,"tag":95,"props":3177,"children":3178},{},[3179,3184,3189,3194],{"type":43,"tag":127,"props":3180,"children":3181},{},[3182],{"type":49,"value":3183},"Static assets (JS, CSS, images)",{"type":43,"tag":127,"props":3185,"children":3186},{},[3187],{"type":49,"value":3188},"Content-addressed URL",{"type":43,"tag":127,"props":3190,"children":3191},{},[3192],{"type":49,"value":3193},"Immutable (1 year)",{"type":43,"tag":127,"props":3195,"children":3196},{},[3197],{"type":49,"value":3198},"No invalidation -- URL changes",{"type":43,"tag":95,"props":3200,"children":3201},{},[3202,3207,3212,3217],{"type":43,"tag":127,"props":3203,"children":3204},{},[3205],{"type":49,"value":3206},"User profile (own)",{"type":43,"tag":127,"props":3208,"children":3209},{},[3210],{"type":49,"value":3211},"Write-through on update",{"type":43,"tag":127,"props":3213,"children":3214},{},[3215],{"type":49,"value":3216},"5 min safety net",{"type":43,"tag":127,"props":3218,"children":3219},{},[3220],{"type":49,"value":3221},"Must see own changes immediately",{"type":43,"tag":95,"props":3223,"children":3224},{},[3225,3230,3235,3240],{"type":43,"tag":127,"props":3226,"children":3227},{},[3228],{"type":49,"value":3229},"User profile (others)",{"type":43,"tag":127,"props":3231,"children":3232},{},[3233],{"type":49,"value":3234},"TTL-only",{"type":43,"tag":127,"props":3236,"children":3237},{},[3238],{"type":49,"value":3239},"5-15 min",{"type":43,"tag":127,"props":3241,"children":3242},{},[3243],{"type":49,"value":3244},"Eventual consistency is fine",{"type":43,"tag":95,"props":3246,"children":3247},{},[3248,3253,3258,3263],{"type":43,"tag":127,"props":3249,"children":3250},{},[3251],{"type":49,"value":3252},"Permissions \u002F access control",{"type":43,"tag":127,"props":3254,"children":3255},{},[3256],{"type":49,"value":3257},"Invalidate on change",{"type":43,"tag":127,"props":3259,"children":3260},{},[3261],{"type":49,"value":3262},"30 sec safety net",{"type":43,"tag":127,"props":3264,"children":3265},{},[3266],{"type":49,"value":3267},"Never TTL-only for security data",{"type":43,"tag":95,"props":3269,"children":3270},{},[3271,3276,3280,3285],{"type":43,"tag":127,"props":3272,"children":3273},{},[3274],{"type":49,"value":3275},"Feature flags",{"type":43,"tag":127,"props":3277,"children":3278},{},[3279],{"type":49,"value":3257},{"type":43,"tag":127,"props":3281,"children":3282},{},[3283],{"type":49,"value":3284},"1 min safety net",{"type":43,"tag":127,"props":3286,"children":3287},{},[3288],{"type":49,"value":3289},"Long TTL delays incident response",{"type":43,"tag":95,"props":3291,"children":3292},{},[3293,3298,3303,3308],{"type":43,"tag":127,"props":3294,"children":3295},{},[3296],{"type":49,"value":3297},"Product catalog",{"type":43,"tag":127,"props":3299,"children":3300},{},[3301],{"type":49,"value":3302},"Event-driven + TTL",{"type":43,"tag":127,"props":3304,"children":3305},{},[3306],{"type":49,"value":3307},"15 min",{"type":43,"tag":127,"props":3309,"children":3310},{},[3311],{"type":49,"value":3312},"Flash sales need faster invalidation",{"type":43,"tag":95,"props":3314,"children":3315},{},[3316,3321,3325,3330],{"type":43,"tag":127,"props":3317,"children":3318},{},[3319],{"type":49,"value":3320},"Search results",{"type":43,"tag":127,"props":3322,"children":3323},{},[3324],{"type":49,"value":3234},{"type":43,"tag":127,"props":3326,"children":3327},{},[3328],{"type":49,"value":3329},"1-5 min",{"type":43,"tag":127,"props":3331,"children":3332},{},[3333],{"type":49,"value":3334},"Eventually consistent by nature",{"type":43,"tag":95,"props":3336,"children":3337},{},[3338,3343,3348,3353],{"type":43,"tag":127,"props":3339,"children":3340},{},[3341],{"type":49,"value":3342},"API rate limit counters",{"type":43,"tag":127,"props":3344,"children":3345},{},[3346],{"type":49,"value":3347},"N\u002FA (not a cache)",{"type":43,"tag":127,"props":3349,"children":3350},{},[3351],{"type":49,"value":3352},"N\u002FA",{"type":43,"tag":127,"props":3354,"children":3355},{},[3356],{"type":49,"value":3357},"Use Redis atomic ops, not caching",{"type":43,"tag":64,"props":3359,"children":3361},{"id":3360},"anti-patterns",[3362],{"type":49,"value":3363},"Anti-Patterns",{"type":43,"tag":406,"props":3365,"children":3367},{"className":408,"code":3366,"language":410,"meta":411,"style":411},"\u002F\u002F No invalidation: cache written, never cleared\nfunction getUser(id) { \u002F* sets cache *\u002F }\nfunction updateUser(id, data) { \u002F* updates DB, doesn't touch cache *\u002F }\n\n\u002F\u002F Unbounded: grows until OOM\nconst queryCache = new Map\u003Cstring, any>();\n\n\u002F\u002F TTL on security data: revoked user keeps access for 15 minutes\nconst permCache = new Map();\nconst TTL = 15 * 60 * 1000;\n\n\u002F\u002F Delete-then-repopulate race: del, then another request reads a lagging replica and re-caches stale data\nawait redis.del(`user:${id}`);\n\n\u002F\u002F Cache key missing context: users see each other's locale-specific content\nawait redis.set(`product:${id}`, JSON.stringify(localizedProduct));\n",[3368],{"type":43,"tag":281,"props":3369,"children":3370},{"__ignoreMap":411},[3371,3379,3418,3463,3470,3478,3531,3538,3546,3578,3619,3626,3634,3688,3695,3703],{"type":43,"tag":417,"props":3372,"children":3373},{"class":419,"line":30},[3374],{"type":43,"tag":417,"props":3375,"children":3376},{"style":671},[3377],{"type":49,"value":3378},"\u002F\u002F No invalidation: cache written, never cleared\n",{"type":43,"tag":417,"props":3380,"children":3381},{"class":419,"line":473},[3382,3386,3391,3395,3400,3404,3408,3413],{"type":43,"tag":417,"props":3383,"children":3384},{"style":423},[3385],{"type":49,"value":426},{"type":43,"tag":417,"props":3387,"children":3388},{"style":429},[3389],{"type":49,"value":3390}," getUser",{"type":43,"tag":417,"props":3392,"children":3393},{"style":435},[3394],{"type":49,"value":438},{"type":43,"tag":417,"props":3396,"children":3397},{"style":441},[3398],{"type":49,"value":3399},"id",{"type":43,"tag":417,"props":3401,"children":3402},{"style":435},[3403],{"type":49,"value":530},{"type":43,"tag":417,"props":3405,"children":3406},{"style":435},[3407],{"type":49,"value":1029},{"type":43,"tag":417,"props":3409,"children":3410},{"style":671},[3411],{"type":49,"value":3412}," \u002F* sets cache *\u002F",{"type":43,"tag":417,"props":3414,"children":3415},{"style":435},[3416],{"type":49,"value":3417}," }\n",{"type":43,"tag":417,"props":3419,"children":3420},{"class":419,"line":26},[3421,3425,3430,3434,3438,3442,3446,3450,3454,3459],{"type":43,"tag":417,"props":3422,"children":3423},{"style":423},[3424],{"type":49,"value":426},{"type":43,"tag":417,"props":3426,"children":3427},{"style":429},[3428],{"type":49,"value":3429}," updateUser",{"type":43,"tag":417,"props":3431,"children":3432},{"style":435},[3433],{"type":49,"value":438},{"type":43,"tag":417,"props":3435,"children":3436},{"style":441},[3437],{"type":49,"value":3399},{"type":43,"tag":417,"props":3439,"children":3440},{"style":435},[3441],{"type":49,"value":605},{"type":43,"tag":417,"props":3443,"children":3444},{"style":441},[3445],{"type":49,"value":1224},{"type":43,"tag":417,"props":3447,"children":3448},{"style":435},[3449],{"type":49,"value":530},{"type":43,"tag":417,"props":3451,"children":3452},{"style":435},[3453],{"type":49,"value":1029},{"type":43,"tag":417,"props":3455,"children":3456},{"style":671},[3457],{"type":49,"value":3458}," \u002F* updates DB, doesn't touch cache *\u002F",{"type":43,"tag":417,"props":3460,"children":3461},{"style":435},[3462],{"type":49,"value":3417},{"type":43,"tag":417,"props":3464,"children":3465},{"class":419,"line":677},[3466],{"type":43,"tag":417,"props":3467,"children":3468},{"emptyLinePlaceholder":760},[3469],{"type":49,"value":763},{"type":43,"tag":417,"props":3471,"children":3472},{"class":419,"line":898},[3473],{"type":43,"tag":417,"props":3474,"children":3475},{"style":671},[3476],{"type":49,"value":3477},"\u002F\u002F Unbounded: grows until OOM\n",{"type":43,"tag":417,"props":3479,"children":3480},{"class":419,"line":957},[3481,3485,3490,3494,3498,3502,3506,3510,3514,3519,3523,3527],{"type":43,"tag":417,"props":3482,"children":3483},{"style":423},[3484],{"type":49,"value":730},{"type":43,"tag":417,"props":3486,"children":3487},{"style":482},[3488],{"type":49,"value":3489}," queryCache ",{"type":43,"tag":417,"props":3491,"children":3492},{"style":435},[3493],{"type":49,"value":740},{"type":43,"tag":417,"props":3495,"children":3496},{"style":435},[3497],{"type":49,"value":1710},{"type":43,"tag":417,"props":3499,"children":3500},{"style":429},[3501],{"type":49,"value":2096},{"type":43,"tag":417,"props":3503,"children":3504},{"style":435},[3505],{"type":49,"value":812},{"type":43,"tag":417,"props":3507,"children":3508},{"style":452},[3509],{"type":49,"value":1723},{"type":43,"tag":417,"props":3511,"children":3512},{"style":435},[3513],{"type":49,"value":605},{"type":43,"tag":417,"props":3515,"children":3516},{"style":452},[3517],{"type":49,"value":3518}," any",{"type":43,"tag":417,"props":3520,"children":3521},{"style":435},[3522],{"type":49,"value":822},{"type":43,"tag":417,"props":3524,"children":3525},{"style":482},[3526],{"type":49,"value":2131},{"type":43,"tag":417,"props":3528,"children":3529},{"style":435},[3530],{"type":49,"value":619},{"type":43,"tag":417,"props":3532,"children":3533},{"class":419,"line":965},[3534],{"type":43,"tag":417,"props":3535,"children":3536},{"emptyLinePlaceholder":760},[3537],{"type":49,"value":763},{"type":43,"tag":417,"props":3539,"children":3540},{"class":419,"line":1063},[3541],{"type":43,"tag":417,"props":3542,"children":3543},{"style":671},[3544],{"type":49,"value":3545},"\u002F\u002F TTL on security data: revoked user keeps access for 15 minutes\n",{"type":43,"tag":417,"props":3547,"children":3548},{"class":419,"line":1153},[3549,3553,3558,3562,3566,3570,3574],{"type":43,"tag":417,"props":3550,"children":3551},{"style":423},[3552],{"type":49,"value":730},{"type":43,"tag":417,"props":3554,"children":3555},{"style":482},[3556],{"type":49,"value":3557}," permCache ",{"type":43,"tag":417,"props":3559,"children":3560},{"style":435},[3561],{"type":49,"value":740},{"type":43,"tag":417,"props":3563,"children":3564},{"style":435},[3565],{"type":49,"value":1710},{"type":43,"tag":417,"props":3567,"children":3568},{"style":429},[3569],{"type":49,"value":2096},{"type":43,"tag":417,"props":3571,"children":3572},{"style":482},[3573],{"type":49,"value":2131},{"type":43,"tag":417,"props":3575,"children":3576},{"style":435},[3577],{"type":49,"value":619},{"type":43,"tag":417,"props":3579,"children":3580},{"class":419,"line":1169},[3581,3585,3590,3594,3599,3603,3607,3611,3615],{"type":43,"tag":417,"props":3582,"children":3583},{"style":423},[3584],{"type":49,"value":730},{"type":43,"tag":417,"props":3586,"children":3587},{"style":482},[3588],{"type":49,"value":3589}," TTL ",{"type":43,"tag":417,"props":3591,"children":3592},{"style":435},[3593],{"type":49,"value":740},{"type":43,"tag":417,"props":3595,"children":3596},{"style":597},[3597],{"type":49,"value":3598}," 15",{"type":43,"tag":417,"props":3600,"children":3601},{"style":435},[3602],{"type":49,"value":1789},{"type":43,"tag":417,"props":3604,"children":3605},{"style":597},[3606],{"type":49,"value":1794},{"type":43,"tag":417,"props":3608,"children":3609},{"style":435},[3610],{"type":49,"value":1789},{"type":43,"tag":417,"props":3612,"children":3613},{"style":597},[3614],{"type":49,"value":1803},{"type":43,"tag":417,"props":3616,"children":3617},{"style":435},[3618],{"type":49,"value":619},{"type":43,"tag":417,"props":3620,"children":3621},{"class":419,"line":1177},[3622],{"type":43,"tag":417,"props":3623,"children":3624},{"emptyLinePlaceholder":760},[3625],{"type":49,"value":763},{"type":43,"tag":417,"props":3627,"children":3628},{"class":419,"line":1185},[3629],{"type":43,"tag":417,"props":3630,"children":3631},{"style":671},[3632],{"type":49,"value":3633},"\u002F\u002F Delete-then-repopulate race: del, then another request reads a lagging replica and re-caches stale data\n",{"type":43,"tag":417,"props":3635,"children":3636},{"class":419,"line":1253},[3637,3642,3646,3650,3655,3659,3663,3668,3672,3676,3680,3684],{"type":43,"tag":417,"props":3638,"children":3639},{"style":625},[3640],{"type":49,"value":3641},"await",{"type":43,"tag":417,"props":3643,"children":3644},{"style":482},[3645],{"type":49,"value":852},{"type":43,"tag":417,"props":3647,"children":3648},{"style":435},[3649],{"type":49,"value":500},{"type":43,"tag":417,"props":3651,"children":3652},{"style":429},[3653],{"type":49,"value":3654},"del",{"type":43,"tag":417,"props":3656,"children":3657},{"style":482},[3658],{"type":49,"value":438},{"type":43,"tag":417,"props":3660,"children":3661},{"style":435},[3662],{"type":49,"value":663},{"type":43,"tag":417,"props":3664,"children":3665},{"style":518},[3666],{"type":49,"value":3667},"user:",{"type":43,"tag":417,"props":3669,"children":3670},{"style":435},[3671],{"type":49,"value":643},{"type":43,"tag":417,"props":3673,"children":3674},{"style":482},[3675],{"type":49,"value":3399},{"type":43,"tag":417,"props":3677,"children":3678},{"style":435},[3679],{"type":49,"value":887},{"type":43,"tag":417,"props":3681,"children":3682},{"style":482},[3683],{"type":49,"value":530},{"type":43,"tag":417,"props":3685,"children":3686},{"style":435},[3687],{"type":49,"value":619},{"type":43,"tag":417,"props":3689,"children":3690},{"class":419,"line":1347},[3691],{"type":43,"tag":417,"props":3692,"children":3693},{"emptyLinePlaceholder":760},[3694],{"type":49,"value":763},{"type":43,"tag":417,"props":3696,"children":3697},{"class":419,"line":1356},[3698],{"type":43,"tag":417,"props":3699,"children":3700},{"style":671},[3701],{"type":49,"value":3702},"\u002F\u002F Cache key missing context: users see each other's locale-specific content\n",{"type":43,"tag":417,"props":3704,"children":3705},{"class":419,"line":1441},[3706,3710,3714,3718,3722,3726,3730,3734,3738,3742,3746,3750,3754,3758,3762,3767],{"type":43,"tag":417,"props":3707,"children":3708},{"style":625},[3709],{"type":49,"value":3641},{"type":43,"tag":417,"props":3711,"children":3712},{"style":482},[3713],{"type":49,"value":852},{"type":43,"tag":417,"props":3715,"children":3716},{"style":435},[3717],{"type":49,"value":500},{"type":43,"tag":417,"props":3719,"children":3720},{"style":429},[3721],{"type":49,"value":2783},{"type":43,"tag":417,"props":3723,"children":3724},{"style":482},[3725],{"type":49,"value":438},{"type":43,"tag":417,"props":3727,"children":3728},{"style":435},[3729],{"type":49,"value":663},{"type":43,"tag":417,"props":3731,"children":3732},{"style":518},[3733],{"type":49,"value":2879},{"type":43,"tag":417,"props":3735,"children":3736},{"style":435},[3737],{"type":49,"value":643},{"type":43,"tag":417,"props":3739,"children":3740},{"style":482},[3741],{"type":49,"value":3399},{"type":43,"tag":417,"props":3743,"children":3744},{"style":435},[3745],{"type":49,"value":887},{"type":43,"tag":417,"props":3747,"children":3748},{"style":435},[3749],{"type":49,"value":605},{"type":43,"tag":417,"props":3751,"children":3752},{"style":482},[3753],{"type":49,"value":929},{"type":43,"tag":417,"props":3755,"children":3756},{"style":435},[3757],{"type":49,"value":500},{"type":43,"tag":417,"props":3759,"children":3760},{"style":429},[3761],{"type":49,"value":1132},{"type":43,"tag":417,"props":3763,"children":3764},{"style":482},[3765],{"type":49,"value":3766},"(localizedProduct))",{"type":43,"tag":417,"props":3768,"children":3769},{"style":435},[3770],{"type":49,"value":619},{"type":43,"tag":64,"props":3772,"children":3774},{"id":3773},"related-traps",[3775],{"type":49,"value":3776},"Related Traps",{"type":43,"tag":1569,"props":3778,"children":3779},{},[3780,3790,3800,3810],{"type":43,"tag":274,"props":3781,"children":3782},{},[3783,3788],{"type":43,"tag":58,"props":3784,"children":3785},{},[3786],{"type":49,"value":3787},"Consistency Models",{"type":49,"value":3789}," -- cache staleness is a consistency problem. Write-through caching avoids the race where delete-then-repopulate reads from a stale replica. See the Consistency Models skill for read-after-write patterns.",{"type":43,"tag":274,"props":3791,"children":3792},{},[3793,3798],{"type":43,"tag":58,"props":3794,"children":3795},{},[3796],{"type":49,"value":3797},"Memory Leaks",{"type":49,"value":3799}," -- every unbounded cache is a memory leak. If it has no max size and no eviction policy, it grows until the process is killed.",{"type":43,"tag":274,"props":3801,"children":3802},{},[3803,3808],{"type":43,"tag":58,"props":3804,"children":3805},{},[3806],{"type":49,"value":3807},"Thundering Herd",{"type":49,"value":3809}," -- cache stampede (popular key expires, all requests hit the database simultaneously) is the thundering herd problem applied to caching. Single-flight and stale-while-revalidate prevent this.",{"type":43,"tag":274,"props":3811,"children":3812},{},[3813,3818],{"type":43,"tag":58,"props":3814,"children":3815},{},[3816],{"type":49,"value":3817},"Denormalization",{"type":49,"value":3819}," -- a cache is a form of denormalization. Every cached value is a copy that must be kept in sync with the source. The consistency obligation is the same.",{"type":43,"tag":3821,"props":3822,"children":3823},"style",{},[3824],{"type":49,"value":3825},"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);}",{"items":3827,"total":3985},[3828,3847,3860,3870,3887,3902,3916,3933,3946,3958,3969,3978],{"slug":3829,"name":3829,"fn":3830,"description":3831,"org":3832,"tags":3833,"stars":3844,"repoUrl":3845,"updatedAt":3846},"trigger-authoring-chat-agent","author durable AI chat agents with Trigger.dev","Author and run a durable AI chat agent with chat.agent from @trigger.dev\u002Fsdk\u002Fai: the per-turn run loop, why you MUST spread ...chat.toStreamTextOptions() first, returning a StreamTextResult vs calling chat.pipe(), the two server actions (chat.createStartSessionAction + auth.createPublicToken), and wiring useChat to useTriggerChatTransport. Load this when building, modifying, or debugging a chat backend (the agent task or its lifecycle hooks) or its React transport, when declaring typed tools or custom data parts, or when migrating a plain AI SDK streamText route to chat.agent.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3834,3837,3840,3841],{"name":3835,"slug":3836,"type":16},"Agents","agents",{"name":3838,"slug":3839,"type":16},"SDK","sdk",{"name":9,"slug":8,"type":16},{"name":3842,"slug":3843,"type":16},"Workflow Automation","workflow-automation",14401,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Ftrigger.dev","2026-07-02T17:12:52.307135",{"slug":3848,"name":3848,"fn":3849,"description":3850,"org":3851,"tags":3852,"stars":3844,"repoUrl":3845,"updatedAt":3859},"trigger-authoring-tasks","author backend Trigger.dev tasks","Covers writing backend Trigger.dev tasks with @trigger.dev\u002Fsdk: defining task() and schemaTask(), the run function and its ctx, retries, waits, queues and concurrency, idempotency keys, run metadata, logging, triggering other tasks (and the Result shape), scheduled\u002Fcron tasks, and the essentials of trigger.config.ts. Load this whenever you are authoring or editing code inside a \u002Ftrigger directory, defining a task, or writing backend code that triggers tasks. Realtime\u002FReact hooks and AI chat are covered by separate skills.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3853,3856,3857,3858],{"name":3854,"slug":3855,"type":16},"Backend","backend",{"name":3838,"slug":3839,"type":16},{"name":9,"slug":8,"type":16},{"name":3842,"slug":3843,"type":16},"2026-07-02T17:12:48.396964",{"slug":3861,"name":3861,"fn":3862,"description":3863,"org":3864,"tags":3865,"stars":3844,"repoUrl":3845,"updatedAt":3869},"trigger-chat-agent-advanced","manage Trigger.dev chat sessions and transports","Advanced and operational chat.agent capabilities for Trigger.dev, loaded on demand. Load this when working on the raw Sessions primitive (sessions \u002F SessionHandle), a custom chat transport or the realtime wire protocol, durable sub-agents (AgentChat, chat.stream.writer), human-in-the-loop, steering, actions, background injection (chat.defer \u002F chat.inject), fast starts (preload, Head Start via @trigger.dev\u002Fsdk\u002Fchat-server), context resilience (compaction, recovery boot, OOM, large payloads), chat.local run-scoped state, offline testing with mockChatAgent, or prerelease\u002Fversion upgrades. For the everyday chat.agent({...}) definition and the useTriggerChatTransport happy path, use the trigger-authoring-chat-agent skill instead.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3866,3867,3868],{"name":3835,"slug":3836,"type":16},{"name":9,"slug":8,"type":16},{"name":3842,"slug":3843,"type":16},"2026-07-02T17:12:51.03018",{"slug":3871,"name":3871,"fn":3872,"description":3873,"org":3874,"tags":3875,"stars":3844,"repoUrl":3845,"updatedAt":3886},"trigger-realtime-and-frontend","subscribe to Trigger.dev runs in realtime","Trigger.dev client\u002Ffrontend surface: subscribe to runs in realtime (runs.subscribeToRun and the @trigger.dev\u002Freact-hooks hook useRealtimeRun), consume metadata and AI\u002Ftext streams in React (useRealtimeStream), trigger tasks from the browser (useTaskTrigger, useRealtimeTaskTrigger), and mint scoped frontend credentials with auth.createPublicToken \u002F auth.createTriggerPublicToken. Load when wiring a frontend (React\u002FNext.js\u002FRemix) or backend-for-frontend to show live run progress, status badges, token streams, trigger buttons, or wait-token approval UIs. NOT for writing the backend task itself (streams.define \u002F metadata.set is trigger-authoring-tasks territory); this is the consumer side.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3876,3879,3882,3885],{"name":3877,"slug":3878,"type":16},"Frontend","frontend",{"name":3880,"slug":3881,"type":16},"React","react",{"name":3883,"slug":3884,"type":16},"Real-time","real-time",{"name":9,"slug":8,"type":16},"2026-07-02T17:12:49.717706",{"slug":3888,"name":3888,"fn":3889,"description":3890,"org":3891,"tags":3892,"stars":3899,"repoUrl":3900,"updatedAt":3901},"trigger-agents","orchestrate AI agents with Trigger.dev","AI agent patterns with Trigger.dev - orchestration, parallelization, routing, evaluator-optimizer, and human-in-the-loop. Use when building LLM-powered tasks that need parallel workers, approval gates, tool calling, or multi-step agent workflows.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3893,3894,3897,3898],{"name":3835,"slug":3836,"type":16},{"name":3895,"slug":3896,"type":16},"Multi-Agent","multi-agent",{"name":9,"slug":8,"type":16},{"name":3842,"slug":3843,"type":16},30,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fskills","2026-04-06T18:54:46.023553",{"slug":3903,"name":3903,"fn":3904,"description":3905,"org":3906,"tags":3907,"stars":3899,"repoUrl":3900,"updatedAt":3915},"trigger-config","configure Trigger.dev project settings","Configure Trigger.dev projects with trigger.config.ts. Use when setting up build extensions for Prisma, Playwright, FFmpeg, Python, or customizing deployment settings.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3908,3911,3914],{"name":3909,"slug":3910,"type":16},"Configuration","configuration",{"name":3912,"slug":3913,"type":16},"Deployment","deployment",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:44.764258",{"slug":3917,"name":3917,"fn":3918,"description":3919,"org":3920,"tags":3921,"stars":3899,"repoUrl":3900,"updatedAt":3932},"trigger-cost-savings","optimize Trigger.dev task costs","Analyze Trigger.dev tasks, schedules, and runs for cost optimization opportunities. Use when asked to reduce spend, optimize costs, audit usage, right-size machines, or review task efficiency. Requires Trigger.dev MCP tools for run analysis.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3922,3925,3928,3931],{"name":3923,"slug":3924,"type":16},"Analytics","analytics",{"name":3926,"slug":3927,"type":16},"Cost Optimization","cost-optimization",{"name":3929,"slug":3930,"type":16},"Operations","operations",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:48.555552",{"slug":3934,"name":3934,"fn":3935,"description":3936,"org":3937,"tags":3938,"stars":3899,"repoUrl":3900,"updatedAt":3945},"trigger-realtime","monitor Trigger.dev tasks in real-time","Subscribe to Trigger.dev task runs in real-time from frontend and backend. Use when building progress indicators, live dashboards, streaming AI\u002FLLM responses, or React components that display task status.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3939,3940,3943,3944],{"name":3877,"slug":3878,"type":16},{"name":3941,"slug":3942,"type":16},"Observability","observability",{"name":3883,"slug":3884,"type":16},{"name":9,"slug":8,"type":16},"2026-04-06T18:54:47.293822",{"slug":3947,"name":3947,"fn":3948,"description":3949,"org":3950,"tags":3951,"stars":3899,"repoUrl":3900,"updatedAt":3957},"trigger-setup","set up Trigger.dev in projects","Set up Trigger.dev in your project. Use when adding Trigger.dev for the first time, creating trigger.config.ts, or initializing the trigger directory.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3952,3953,3956],{"name":3909,"slug":3910,"type":16},{"name":3954,"slug":3955,"type":16},"Local Development","local-development",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:42.280816",{"slug":3959,"name":3959,"fn":3960,"description":3961,"org":3962,"tags":3963,"stars":3899,"repoUrl":3900,"updatedAt":3968},"trigger-tasks","build durable background tasks with Trigger.dev","Build AI agents, workflows and durable background tasks with Trigger.dev. Use when creating tasks, triggering jobs, handling retries, scheduling cron jobs, or implementing queues and concurrency control.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3964,3965,3966,3967],{"name":3835,"slug":3836,"type":16},{"name":3854,"slug":3855,"type":16},{"name":9,"slug":8,"type":16},{"name":3842,"slug":3843,"type":16},"2026-04-06T18:54:43.514369",{"slug":3970,"name":3970,"fn":3971,"description":3972,"org":3973,"tags":3974,"stars":26,"repoUrl":27,"updatedAt":3977},"staff-engineering-skills-backpressure","implement backpressure in streaming pipelines","Prevent unbounded resource growth when producers outpace consumers. Use when writing producer-consumer code, queue processing, batch operations, fan-out patterns, streaming pipelines, or any code where work is generated faster than it can be processed. Activates on patterns like Promise.all on dynamic-sized arrays, unbounded in-memory queues, producer loops without depth checks, fire-and-forget async calls in loops, or any buffer between a producer and consumer without a size limit.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3975,3976],{"name":18,"slug":19,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:42.723559",{"slug":4,"name":4,"fn":5,"description":6,"org":3979,"tags":3980,"stars":26,"repoUrl":27,"updatedAt":28},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3981,3982,3983,3984],{"name":18,"slug":19,"type":16},{"name":24,"slug":25,"type":16},{"name":21,"slug":22,"type":16},{"name":14,"slug":15,"type":16},26,{"items":3987,"total":1441},[3988,3993,4000,4010,4022,4035,4047],{"slug":3970,"name":3970,"fn":3971,"description":3972,"org":3989,"tags":3990,"stars":26,"repoUrl":27,"updatedAt":3977},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3991,3992],{"name":18,"slug":19,"type":16},{"name":14,"slug":15,"type":16},{"slug":4,"name":4,"fn":5,"description":6,"org":3994,"tags":3995,"stars":26,"repoUrl":27,"updatedAt":28},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3996,3997,3998,3999],{"name":18,"slug":19,"type":16},{"name":24,"slug":25,"type":16},{"name":21,"slug":22,"type":16},{"name":14,"slug":15,"type":16},{"slug":4001,"name":4001,"fn":4002,"description":4003,"org":4004,"tags":4005,"stars":26,"repoUrl":27,"updatedAt":4009},"staff-engineering-skills-cardinality","prevent cardinality traps in systems code","Detect and prevent cardinality traps in systems code. Use when writing code that iterates over collections, stores items in memory, creates per-entity resources, or fans out operations across a set of items. Activates on patterns like loops over query results, in-memory Maps\u002FSets populated from databases, or \"one X per Y\" resource allocation.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[4006,4007,4008],{"name":18,"slug":19,"type":16},{"name":21,"slug":22,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:40.264608",{"slug":4011,"name":4011,"fn":4012,"description":4013,"org":4014,"tags":4015,"stars":26,"repoUrl":27,"updatedAt":4021},"staff-engineering-skills-clock-skew","prevent clock skew bugs in distributed systems","Prevent bugs caused by assuming clocks are synchronized or monotonic. Use when writing code that compares timestamps across machines, measures durations, sets lock expiry, orders distributed events, deduplicates by time window, or uses Date.now() for anything other than logging or display. Activates on patterns like Date.now() used for duration measurement, absolute timestamp expiry shared across machines, wall clock timestamps for event ordering, last-write-wins conflict resolution with timestamps, or timeout calculations using wall clock time.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[4016,4017,4020],{"name":18,"slug":19,"type":16},{"name":4018,"slug":4019,"type":16},"Debugging","debugging",{"name":21,"slug":22,"type":16},"2026-06-17T08:40:37.803541",{"slug":4023,"name":4023,"fn":4024,"description":4025,"org":4026,"tags":4027,"stars":26,"repoUrl":27,"updatedAt":4034},"staff-engineering-skills-consistency-models","manage consistency models in distributed systems","Prevent stale read bugs caused by replica lag, cache staleness, and index delay. Use when writing code that reads data after writing it, uses read replicas, caches query results, reads from search indexes, or builds event-driven read models. Activates on patterns like create-then-redirect, update-then-read, cache-aside with TTL, search-after-create, or any write followed by a read that might hit a different data source.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[4028,4029,4032,4033],{"name":18,"slug":19,"type":16},{"name":4030,"slug":4031,"type":16},"Database","database",{"name":21,"slug":22,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:46.442182",{"slug":4036,"name":4036,"fn":4037,"description":4038,"org":4039,"tags":4040,"stars":26,"repoUrl":27,"updatedAt":4046},"staff-engineering-skills-denormalization","prevent data model denormalization traps","Detect and prevent denormalization traps when designing data models. Use when writing code that copies fields between tables, embeds related data in documents, caches composed objects, or adds redundant columns to avoid joins. Activates on patterns like storing derived\u002Fcopied data, syncing fields across tables, or embedding nested objects in document stores.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[4041,4042,4045],{"name":18,"slug":19,"type":16},{"name":4043,"slug":4044,"type":16},"Data Modeling","data-modeling",{"name":4030,"slug":4031,"type":16},"2026-06-17T08:40:53.835868",{"slug":4048,"name":4048,"fn":4049,"description":4050,"org":4051,"tags":4052,"stars":26,"repoUrl":27,"updatedAt":4058},"staff-engineering-skills-distributed-system-fallacies","design resilient distributed systems","Prevent failures caused by treating network calls like function calls. Use when writing code that calls external services, splits a monolith into microservices, chains multiple API calls, orchestrates distributed workflows, or handles requests that depend on other services. Activates on patterns like sequential service calls without timeouts, fetch\u002Faxios calls without error handling, multi-service writes without compensation, hardcoded service URLs, or any code that assumes the network is reliable, fast, or free.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[4053,4056,4057],{"name":4054,"slug":4055,"type":16},"API Development","api-development",{"name":18,"slug":19,"type":16},{"name":21,"slug":22,"type":16},"2026-06-17T08:40:47.666795"]