[{"data":1,"prerenderedAt":261},["ShallowReactive",2],{"content-/blog/caching-strategy":3,"related-blog":236},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"keywords":10,"author":11,"date":12,"category":13,"image":14,"body":15,"_type":230,"_id":231,"_source":232,"_file":233,"_stem":234,"_extension":235},"/blog/caching-strategy","blog",false,"","缓存策略设计","智能缓存机制，减少重复计算，提升响应速度","缓存策略设计, Blog, HTMLPAGE","HTMLPAGE","2025-11-26","待分类","/content-images/blog/blog.jpg",{"type":16,"children":17,"toc":218},"root",[18,26,32,52,57,65,70,75,81,86,91,137,143,156,161,174,179,187,191,196],{"type":19,"tag":20,"props":21,"children":22},"element","p",{},[23],{"type":24,"value":25},"text","缓存策略是提升性能与减轻后端负载的重要手段。本文讨论多层缓存（浏览器、CDN、应用）设计原则。",{"type":19,"tag":27,"props":28,"children":30},"h3",{"id":29},"缓存层次",[31],{"type":24,"value":29},{"type":19,"tag":33,"props":34,"children":35},"ul",{},[36,42,47],{"type":19,"tag":37,"props":38,"children":39},"li",{},[40],{"type":24,"value":41},"浏览器缓存：利用 Cache-Control 与 ETag 控制资源刷新。",{"type":19,"tag":37,"props":43,"children":44},{},[45],{"type":24,"value":46},"CDN 边缘缓存：将热点资源放到地理近的边缘节点。",{"type":19,"tag":37,"props":48,"children":49},{},[50],{"type":24,"value":51},"应用缓存/Redis：缓存计算密集或频繁查询的数据。",{"type":19,"tag":27,"props":53,"children":55},{"id":54},"缓存失效策略",[56],{"type":24,"value":54},{"type":19,"tag":33,"props":58,"children":59},{},[60],{"type":19,"tag":37,"props":61,"children":62},{},[63],{"type":24,"value":64},"主动失效（通过变更事件触发）或基于版本号的 Key 设计更可控。",{"type":19,"tag":27,"props":66,"children":68},{"id":67},"结论",[69],{"type":24,"value":67},{"type":19,"tag":20,"props":71,"children":72},{},[73],{"type":24,"value":74},"结合多层缓存与合理的失效策略可以在保证数据一致性的前提下显著提升吞吐与用户体验。",{"type":19,"tag":76,"props":77,"children":79},"h2",{"id":78},"初步纲要",[80],{"type":24,"value":78},{"type":19,"tag":20,"props":82,"children":83},{},[84],{"type":24,"value":85},"良好的缓存策略能大幅提升生成系统的响应速度与吞吐，同时降低后端负载。本文概述浏览器缓存、CDN 缓存与服务端缓存的设计建议。",{"type":19,"tag":76,"props":87,"children":89},{"id":88},"浏览器端缓存",[90],{"type":24,"value":88},{"type":19,"tag":33,"props":92,"children":93},{},[94,132],{"type":19,"tag":37,"props":95,"children":96},{},[97,99,106,108,114,116,122,124,130],{"type":24,"value":98},"利用 ",{"type":19,"tag":100,"props":101,"children":103},"code",{"className":102},[],[104],{"type":24,"value":105},"Cache-Control",{"type":24,"value":107},"（",{"type":19,"tag":100,"props":109,"children":111},{"className":110},[],[112],{"type":24,"value":113},"max-age",{"type":24,"value":115},"、",{"type":19,"tag":100,"props":117,"children":119},{"className":118},[],[120],{"type":24,"value":121},"immutable",{"type":24,"value":123},"）和 ",{"type":19,"tag":100,"props":125,"children":127},{"className":126},[],[128],{"type":24,"value":129},"ETag/Last-Modified",{"type":24,"value":131}," 实现长缓存与条件请求，减少重复下载。",{"type":19,"tag":37,"props":133,"children":134},{},[135],{"type":24,"value":136},"对动态内容设置合适的缓存策略，例如短 TTL 或通过版本号控制缓存失效。",{"type":19,"tag":76,"props":138,"children":140},{"id":139},"cdn-与边缘缓存",[141],{"type":24,"value":142},"CDN 与边缘缓存",{"type":19,"tag":33,"props":144,"children":145},{},[146,151],{"type":19,"tag":37,"props":147,"children":148},{},[149],{"type":24,"value":150},"将静态资源（图片、静态 HTML、JS/CSS）放到 CDN，使用路径或查询参数作为缓存键管理版本。",{"type":19,"tag":37,"props":152,"children":153},{},[154],{"type":24,"value":155},"对于个性化内容考虑边缘缓存 + 缓存键化（按用户段或 cookie 标记），并设置回源降级策略。",{"type":19,"tag":76,"props":157,"children":159},{"id":158},"服务端缓存与生成缓存",[160],{"type":24,"value":158},{"type":19,"tag":33,"props":162,"children":163},{},[164,169],{"type":19,"tag":37,"props":165,"children":166},{},[167],{"type":24,"value":168},"在生成流程中缓存不可变或少变的中间产物（模板渲染片段、第三方 API 响应），使用 Redis/Memory Cache 提高命中率。",{"type":19,"tag":37,"props":170,"children":171},{},[172],{"type":24,"value":173},"对于长时间生成任务，返回任务 ID 并允许客户端轮询或使用 SSE 通知完成，避免重复发起相同任务。",{"type":19,"tag":76,"props":175,"children":177},{"id":176},"缓存失效与一致性",[178],{"type":24,"value":176},{"type":19,"tag":33,"props":180,"children":181},{},[182],{"type":19,"tag":37,"props":183,"children":184},{},[185],{"type":24,"value":186},"使用语义版本号或内容散列（content-hash）确保更新时自动失效，避免手工清理 CDN 缓存。",{"type":19,"tag":188,"props":189,"children":190},"hr",{},[],{"type":19,"tag":20,"props":192,"children":193},{},[194],{"type":24,"value":195},"相关链接：",{"type":19,"tag":33,"props":197,"children":198},{},[199,209],{"type":19,"tag":37,"props":200,"children":201},{},[202],{"type":19,"tag":203,"props":204,"children":206},"a",{"href":205},"/blog",[207],{"type":24,"value":208},"返回博客分类",{"type":19,"tag":37,"props":210,"children":211},{},[212],{"type":19,"tag":203,"props":213,"children":215},{"href":214},"/blog/topic/multi-agent-system",[216],{"type":24,"value":217},"查看热门话题",{"title":7,"searchDepth":219,"depth":219,"links":220},3,[221,222,223,224,226,227,228,229],{"id":29,"depth":219,"text":29},{"id":54,"depth":219,"text":54},{"id":67,"depth":219,"text":67},{"id":78,"depth":225,"text":78},2,{"id":88,"depth":225,"text":88},{"id":139,"depth":225,"text":142},{"id":158,"depth":225,"text":158},{"id":176,"depth":225,"text":176},"markdown","content:blog:caching-strategy.md","content","blog/caching-strategy.md","blog/caching-strategy","md",[237,245,253],{"_path":238,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":239,"description":240,"keywords":241,"author":11,"date":12,"category":13,"image":14,"_type":230,"_id":242,"_source":232,"_file":243,"_stem":244,"_extension":235},"/blog/2025-q1-updates","2025 Q1 产品更新","第一季度重大功能发布：AI 生成优化、新模板上线、编辑器增强等","2025 Q1 产品更新, Blog, HTMLPAGE","content:blog:2025-q1-updates.md","blog/2025-q1-updates.md","blog/2025-q1-updates",{"_path":246,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":247,"description":248,"keywords":249,"author":11,"date":12,"category":13,"image":14,"_type":230,"_id":250,"_source":232,"_file":251,"_stem":252,"_extension":235},"/blog/2025-roadmap","2025 产品路线图","展望 2025 年的产品规划：AI 能力增强、模板扩充、国际化等","2025 产品路线图, Blog, HTMLPAGE","content:blog:2025-roadmap.md","blog/2025-roadmap.md","blog/2025-roadmap",{"_path":254,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":255,"description":256,"keywords":257,"author":11,"date":12,"category":13,"image":14,"_type":230,"_id":258,"_source":232,"_file":259,"_stem":260,"_extension":235},"/blog/ab-testing","A/B 测试","通过 A/B 测试验证设计方案","A/B 测试, Blog, HTMLPAGE","content:blog:ab-testing.md","blog/ab-testing.md","blog/ab-testing",1774945288176]