{"id":58483,"date":"2025-08-16T11:25:21","date_gmt":"2025-08-16T03:25:21","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/58483.html"},"modified":"2025-08-16T11:25:21","modified_gmt":"2025-08-16T03:25:21","slug":"c%e5%90%8e%e7%ab%af%e7%bc%96%e7%a8%8b-%e6%9e%84%e5%bb%ba%e9%ab%98%e6%80%a7%e8%83%bd%e5%90%8e%e7%ab%af%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93%e3%80%81api-%e4%b8%8e-web-%e6%9c%8d%e5%8a%a1%e5%99%a8-7","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/58483.html","title":{"rendered":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 7 \u5904\u7406\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u7f13\u5b58"},"content":{"rendered":"<h2 id=\"aid_217\" style=\"text-align:justify\"><span style=\"color:#000000\">C&#043;&#043;\u540e\u7aef\u5f00\u53d1\u4e2d\u7684\u7f13\u5b58\u6280\u672f<\/span><\/h2>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u6280\u672f\u7684\u8fd0\u7528\u5bf9\u4e8e\u9ad8\u6027\u80fd\u7f51\u7edc\u5e94\u7528\u7684\u8fd0\u884c\u81f3\u5173\u91cd\u8981\u3002\u00a0\u5b83\u4f5c\u4e3a\u5b58\u50a8\u4e2d\u95f4\u72b6\u6001\u6570\u636e\u7684\u7ec4\u4ef6&#xff0c;\u80fd\u591f\u663e\u8457\u52a0\u5feb\u540e\u7eed\u76f8\u540c\u6570\u636e\u8bf7\u6c42\u7684\u54cd\u5e94\u901f\u5ea6\u3002\u00a0\u7f13\u5b58\u4e2d\u4fdd\u5b58\u7684\u6570\u636e\u65e2\u53ef\u4ee5\u662f\u5176\u4ed6\u4f4d\u7f6e\u5b58\u50a8\u6570\u636e\u7684\u526f\u672c&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u5148\u524d\u8ba1\u7b97\u7684\u7ed3\u679c\u3002\u00a0\u901a\u8fc7\u7f13\u5b58\u6280\u672f&#xff0c;\u60a8\u53ef\u4ee5\u5c06\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\u6216\u6587\u4ef6\u4ee5\u6bd4\u4f20\u7edf\u76f4\u63a5\u8bbf\u95ee\u65b9\u5f0f\u5feb\u5f97\u591a\u7684\u901f\u5ea6\u8fdb\u884c\u5b58\u50a8\u548c\u68c0\u7d22\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u4e4b\u95f4\u6dfb\u52a0\u7f13\u5b58\u4e2d\u95f4\u5c42\u80fd\u6709\u6548\u63d0\u5347\u7cfb\u7edf\u6027\u80fd\u3002\u00a0\u8fd9\u5728\u670d\u52a1\u5668\u7aef\u7f16\u7a0b\u4e2d\u5c24\u4e3a\u6709\u76ca&#xff0c;\u65e2\u80fd\u51cf\u8f7b\u670d\u52a1\u5668\u8d1f\u8f7d&#xff0c;\u7f29\u77ed Web \u5e94\u7528\u54cd\u5e94\u65f6\u95f4&#xff0c;\u53c8\u80fd\u5168\u9762\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u8d28\u91cf\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728\u670d\u52a1\u5668\u7aef\u7f16\u7a0b\u4e2d&#xff0c;\u7f13\u5b58\u6280\u672f\u6709\u591a\u79cd\u4e0d\u540c\u7684\u5e94\u7528\u65b9\u5f0f\u3002\u00a0\u670d\u52a1\u5668\u7aef\u7f13\u5b58\u53ef\u4ee5\u5305\u62ec\u5b58\u50a8\u9ad8\u5f00\u9500\u6570\u636e\u5e93\u67e5\u8be2\u7ed3\u679c\u3001\u6574\u5f20\u7f51\u9875\u5185\u5bb9&#xff0c;\u751a\u81f3\u662f API \u54cd\u5e94\u6570\u636e\u3002\u00a0\u4e3e\u4f8b\u6765\u8bf4&#xff0c;\u670d\u52a1\u5668\u7aef\u7f13\u5b58\u53ef\u80fd\u6d89\u53ca\u7f51\u9875\u5b58\u50a8\u3002\u00a0\u57fa\u672c\u4e0a&#xff0c;\u4efb\u4f55\u88ab\u9891\u7e41\u8bf7\u6c42\u3001\u751f\u6210\u8017\u65f6\u8f83\u957f\u4e14\u8bbf\u95ee\u91cf\u5927\u7684\u5185\u5bb9\u90fd\u9002\u5408\u91c7\u7528\u7f13\u5b58\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u662f C&#043;&#043;\u540e\u7aef\u5f00\u53d1\u4e2d\u7684\u5173\u952e\u7ec4\u4ef6&#xff0c;\u5bf9\u4e8e\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u901f\u5ea6\u548c\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u00a0\u73b0\u4ee3 C&#043;&#043;\u5e94\u7528\u5c24\u5176\u662f\u540e\u7aef\u7f51\u7edc\u670d\u52a1&#xff0c;\u901a\u5e38\u9700\u8981\u5feb\u901f\u54cd\u5e94\u548c\u4f4e\u5ef6\u8fdf\u3002\u00a0\u7f13\u5b58\u6280\u672f\u80fd\u663e\u8457\u6539\u5584\u54cd\u5e94\u65f6\u95f4&#xff0c;\u51cf\u8f7b\u6570\u636e\u5e93\u8d1f\u8f7d&#xff0c;\u6700\u7ec8\u63d0\u4f9b\u66f4\u6d41\u7545\u3001\u66f4\u5feb\u901f\u7684\u7528\u6237\u4f53\u9a8c\u3002\u00a0\u65e0\u8bba\u662f\u5904\u7406\u6bcf\u79d2\u9ad8\u5e76\u53d1\u8bf7\u6c42\u8fd8\u662f\u6267\u884c\u590d\u6742\u8fd0\u7b97&#xff0c;\u8fd9\u4e00\u4f18\u52bf\u90fd\u540c\u6837\u9002\u7528\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u672c\u7ae0\u5c06\u6df1\u5165\u63a2\u8ba8\u7f13\u5b58\u6280\u672f\u7684\u65b9\u65b9\u9762\u9762\u3002\u00a0\u6211\u4eec\u5c06\u8ba8\u8bba\u7f13\u5b58\u5728\u540e\u7aef\u5f00\u53d1\u4e2d\u7684\u91cd\u8981\u6027\u3001\u5404\u79cd\u7f13\u5b58\u7c7b\u578b&#xff0c;\u4ee5\u53ca\u5728 C&#043;&#043;\u73af\u5883\u4e2d\u5b9e\u73b0\u7f13\u5b58\u6240\u9700\u7684\u6b65\u9aa4\u3002\u00a0\u540c\u65f6\u4e5f\u4f1a\u5206\u6790\u7f13\u5b58\u51b3\u7b56\u5e26\u6765\u7684\u5f71\u54cd&#xff0c;\u7279\u522b\u662f\u8fd9\u4e9b\u51b3\u7b56\u5982\u4f55\u5f71\u54cd\u540e\u7aef\u670d\u52a1\u7684\u6027\u80fd\u548c\u6269\u5c55\u6027\u3002<\/span><\/p>\n<h2 id=\"aid_148\" style=\"text-align:justify\"><span style=\"color:#000000\">\u670d\u52a1\u5668\u7aef\u7f13\u5b58\u7b56\u7565<\/span><\/h2>\n<p><span style=\"color:#000000\">\u6839\u636e\u540e\u7aef\u670d\u52a1\u7684\u9700\u6c42&#xff0c;\u60a8\u53ef\u4ee5\u5229\u7528\u591a\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u7f13\u5b58\u3002\u00a0\u672c\u8282\u6211\u4eec\u5c06\u63a2\u8ba8\u56db\u79cd\u7c7b\u578b&#xff1a;\u5185\u5b58\u7f13\u5b58\u3001\u6570\u636e\u5e93\u7f13\u5b58\u3001CDN \u548c HTTP \u7f13\u5b58\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"142\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250816032518-689ffa1edadcf.png\" width=\"687\" \/><\/p>\n<p><span style=\"color:#000000\">\u56fe7.1 \u670d\u52a1\u5668\u7aef\u7f13\u5b58\u7b56\u7565\u7c7b\u578b<\/span><\/p>\n<p><span style=\"color:#000000\">\u5185\u5b58\u7f13\u5b58<\/span><\/p>\n<p><span style=\"color:#000000\">\u5185\u5b58\u7f13\u5b58\u662f\u4e00\u79cd\u5c06\u6570\u636e\u5b58\u50a8\u5728\u670d\u52a1\u5668\u5185\u5b58\u4e2d\u4ee5\u5b9e\u73b0\u5feb\u901f\u8bbf\u95ee\u7684\u65b9\u6cd5\u3002\u00a0\u5b83\u7279\u522b\u9002\u7528\u4e8e\u9891\u7e41\u8bfb\u53d6\u4f46\u8f83\u5c11\u66f4\u65b0\u7684\u6570\u636e\u3002\u00a0\u6700\u77e5\u540d\u4e14\u5e7f\u6cdb\u4f7f\u7528\u7684\u5185\u5b58\u7f13\u5b58\u7cfb\u7edf\u662f Redis&#xff0c;\u4e0d\u8fc7 Memcached \u7b49\u5176\u4ed6\u7cfb\u7edf\u4e5f\u5e38\u88ab\u4f7f\u7528\u3002\u00a0\u7531\u4e8e\u5185\u5b58\u8bbf\u95ee\u901f\u5ea6\u8fdc\u5feb\u4e8e\u78c1\u76d8\u8bbf\u95ee&#xff0c;\u5185\u5b58\u7f13\u5b58\u80fd\u663e\u8457\u964d\u4f4e\u6570\u636e\u68c0\u7d22\u5ef6\u8fdf\u3002\u00a0\u5b83\u901a\u5e38\u7528\u4e8e\u7f13\u5b58\u590d\u6742\u8ba1\u7b97\u7ed3\u679c\u3001\u6570\u636e\u5e93\u8c03\u7528\u7ed3\u679c\u548c\u4f1a\u8bdd\u6570\u636e\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4f8b\u5982&#xff0c;\u5728 C&#043;&#043;\u540e\u7aef\u4e2d&#xff0c;\u60a8\u53ef\u80fd\u4f7f\u7528\u5185\u5b58\u7f13\u5b58\u6765\u5b58\u50a8\u7528\u6237\u4f1a\u8bdd\u6570\u636e\u3002\u00a0\u7531\u4e8e\u8fd9\u4e9b\u6570\u636e\u7ecf\u5e38\u88ab\u8bbf\u95ee\u4f46\u5f88\u5c11\u53d8\u5316&#xff0c;\u5c06\u5176\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u53ef\u4f7f\u5e94\u7528\u7a0b\u5e8f\u54cd\u5e94\u66f4\u8fc5\u901f\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u6570\u636e\u5e93\u7f13\u5b58<\/span><\/p>\n<p><span style=\"color:#000000\">\u6570\u636e\u5e93\u7f13\u5b58\u662f\u6307\u7f13\u5b58\u5bf9\u6570\u636e\u5e93\u67e5\u8be2\u7684\u7ed3\u679c\u3002\u00a0\u7531\u4e8e\u6570\u636e\u5e93\u5e38\u5e38\u4f1a\u6210\u4e3a\u6027\u80fd\u74f6\u9888&#xff0c;\u7279\u522b\u662f\u5728\u5904\u7406\u590d\u6742\u67e5\u8be2\u6216\u5927\u578b\u6570\u636e\u96c6\u65f6&#xff0c;\u7f13\u5b58\u6570\u636e\u5e93\u7ed3\u679c\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u540e\u7aef\u7cfb\u7edf\u7684\u6027\u80fd\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4f8b\u5982&#xff0c;\u5982\u679c\u4f60\u7684 C&#043;&#043;\u540e\u7aef\u6b63\u5728\u6267\u884c\u590d\u6742\u7684 SQL \u67e5\u8be2\u6765\u83b7\u53d6\u535a\u5ba2\u6587\u7ae0&#xff0c;\u7f13\u5b58\u8fd9\u4e9b\u67e5\u8be2\u7ed3\u679c\u80fd\u4f7f\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u66f4\u4f18\u3002\u00a0\u4e0b\u6b21\u9700\u8981\u76f8\u540c\u6570\u636e\u65f6&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6&#xff0c;\u800c\u65e0\u9700\u518d\u6b21\u6267\u884c\u76f8\u540c\u7684 SQL \u67e5\u8be2\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5185\u5bb9\u5206\u53d1\u7f51\u7edc&#xff08;CDN&#xff09;\u7f13\u5b58<\/span><\/p>\n<p><span style=\"color:#000000\">CDN \u662f\u4e00\u79cd\u5c06\u6570\u636e\u5b58\u50a8\u5728\u7f51\u7edc\u8fb9\u7f18\u7684\u7f13\u5b58\u7c7b\u578b\u3002\u00a0\u8fd9\u79cd\u7f13\u5b58\u7279\u522b\u9002\u7528\u4e8e\u4e0d\u7ecf\u5e38\u53d8\u5316\u7684\u9759\u6001\u5185\u5bb9&#xff0c;\u5982\u56fe\u7247\u3001CSS \u548c JavaScript \u6587\u4ef6\u3002\u00a0\u901a\u8fc7\u5c06\u8fd9\u4e9b\u5185\u5bb9\u5b58\u50a8\u5728\u66f4\u63a5\u8fd1\u8bbf\u95ee\u7528\u6237\u7684\u4f4d\u7f6e&#xff0c;CDN \u80fd\u663e\u8457\u964d\u4f4e\u5ef6\u8fdf\u5e76\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728 C&#043;&#043;\u540e\u7aef\u73af\u5883\u4e2d&#xff0c;\u53ef\u4ee5\u4f7f\u7528 CDN \u6765\u6258\u7ba1 Web \u5e94\u7528\u7684\u9759\u6001\u8d44\u6e90\u3002\u00a0\u4f8b\u5982&#xff0c;\u53ef\u4ee5\u5c06\u535a\u5ba2\u6587\u7ae0\u4e2d\u7684\u56fe\u7247\u5b58\u50a8\u5728 CDN \u4e0a&#xff0c;\u786e\u4fdd\u65e0\u8bba\u7528\u6237\u4f4d\u4e8e\u4f55\u5904\u90fd\u80fd\u5feb\u901f\u53ef\u9760\u5730\u8bbf\u95ee\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">HTTP \u7f13\u5b58<\/span><\/p>\n<p><span style=\"color:#000000\">HTTP \u7f13\u5b58\u662f\u6307\u5b58\u50a8 HTTP \u8bf7\u6c42\u5185\u5bb9\u4ee5\u4f9b\u540e\u7eed\u54cd\u5e94\u91cd\u590d\u4f7f\u7528\u3002\u00a0\u8fd9\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd HTTP \u5934\u6765\u5b9e\u73b0&#xff0c;\u8fd9\u4e9b\u5934\u4fe1\u606f\u63a7\u5236\u7740\u7f13\u5b58\u7684\u65b9\u5f0f\u3001\u65f6\u673a\u548c\u6301\u7eed\u65f6\u95f4\u3002\u00a0\u8fd9\u662f\u4e00\u79cd\u7f13\u5b58\u7f51\u9875\u8d44\u6e90\u7684\u6709\u6548\u65b9\u6cd5&#xff0c;\u80fd\u51cf\u8f7b\u670d\u52a1\u5668\u8d1f\u8f7d\u5e76\u63d0\u9ad8\u54cd\u5e94\u901f\u5ea6\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u53ef\u4ee5\u5728 C&#043;&#043;\u540e\u7aef\u4e2d\u5229\u7528 HTTP \u7f13\u5b58\u6765\u7f13\u5b58\u7279\u5b9a API \u7aef\u70b9\u7684\u54cd\u5e94\u3002\u00a0\u4f8b\u5982&#xff0c;\u5982\u679c\u6709\u4e00\u4e2a\u83b7\u53d6\u6240\u6709\u535a\u5ba2\u6587\u7ae0\u5217\u8868\u7684\u7aef\u70b9&#xff0c;\u53ef\u4ee5\u7f13\u5b58\u8be5\u54cd\u5e94&#xff0c;\u4f7f\u540e\u7eed\u8bf7\u6c42\u7684\u54cd\u5e94\u901f\u5ea6\u66f4\u5feb\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8fd9\u4e9b\u4e0d\u540c\u7684\u6570\u636e\u7f13\u5b58\u6280\u672f\u5404\u5177\u4f18\u52bf&#xff0c;\u53ef\u5e94\u7528\u4e8e\u591a\u79cd\u573a\u666f\u3002\u00a0\u9009\u62e9\u7f13\u5b58\u65b9\u6cd5\u65f6&#xff0c;\u5e94\u7528\u7a0b\u5e8f\u7684\u5177\u4f53\u9700\u6c42\u3001\u5904\u7406\u7684\u6570\u636e\u7c7b\u578b\u4ee5\u53ca\u671f\u671b\u5b9e\u73b0\u7684\u6027\u80fd\u4f18\u5316\u76ee\u6807\u901a\u5e38\u662f\u91cd\u8981\u8003\u91cf\u56e0\u7d20\u3002\u00a0\u901a\u8fc7\u6709\u6548\u8fd0\u7528\u8fd9\u4e9b\u7f13\u5b58\u6280\u672f&#xff0c;\u60a8\u80fd\u663e\u8457\u63d0\u5347 C&#043;&#043;\u540e\u7aef\u670d\u52a1\u7684\u6027\u80fd\u8868\u73b0\u3001\u54cd\u5e94\u901f\u5ea6\u4ee5\u53ca\u6240\u63d0\u4f9b\u7684\u7528\u6237\u4f53\u9a8c\u8d28\u91cf\u3002<\/span><\/p>\n<h2 id=\"aid_296\" style=\"text-align:justify\"><span style=\"color:#000000\">\u6570\u636e\u5e93\u7f13\u5b58\u8fc7\u7a0b<\/span><\/h2>\n<p><span style=\"color:#000000\">\u6570\u636e\u5e93\u7f13\u5b58\u662f\u4e00\u4e2a\u80fd\u663e\u8457\u4f18\u5316\u5e94\u7528\u7a0b\u5e8f\u4e0e\u5176\u6570\u636e\u5e93\u95f4\u4ea4\u4e92\u7684\u8fc7\u7a0b\u3002\u00a0\u5bf9\u4e8e\u50cf MongoDB \u8fd9\u6837\u7684 NoSQL \u6570\u636e\u5e93&#xff0c;\u5176\u7f13\u5b58\u8fc7\u7a0b\u9075\u5faa\u4ee5\u4e0b\u57fa\u672c\u6b65\u9aa4&#xff1a;<\/span><\/p>\n<p><span style=\"color:#000000\">\u67e5\u8be2\u6267\u884c<\/span><\/p>\n<p><span style=\"color:#000000\">\u6700\u521d&#xff0c;\u5e94\u7528\u7a0b\u5e8f\u6267\u884c\u6570\u636e\u5e93\u67e5\u8be2\u3002\u00a0\u8be5\u67e5\u8be2\u53ef\u80fd\u6d89\u53ca\u6570\u636e\u83b7\u53d6\u3001\u66f4\u65b0\u3001\u5220\u9664\u6216\u521b\u5efa\u64cd\u4f5c\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u67e5\u8be2\u7ed3\u679c\u5b58\u50a8<\/span><\/p>\n<p><span style=\"color:#000000\">\u5f53\u6570\u636e\u5e93\u67e5\u8be2\u7ed3\u679c\u8fd4\u56de\u540e&#xff0c;\u5e94\u7528\u7a0b\u5e8f\u4e0d\u4f1a\u5728\u4f7f\u7528\u540e\u7acb\u5373\u4e22\u5f03\u8fd9\u4e9b\u6570\u636e&#xff0c;\u800c\u662f\u5c06\u5176\u5b58\u50a8\u5728\u7f13\u5b58\u4e2d\u3002\u00a0\u7f13\u5b58\u901a\u5e38\u5b9e\u73b0\u4e3a\u952e\u503c\u5b58\u50a8&#xff0c;\u5176\u4e2d\u67e5\u8be2\u8bed\u53e5\u4f5c\u4e3a\u952e&#xff0c;\u67e5\u8be2\u7ed3\u679c\u4f5c\u4e3a\u503c\u3002\u00a0\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u7f13\u5b58\u6570\u636e\u4ee3\u8868\u7279\u5b9a\u65f6\u95f4\u70b9\u7684\u6570\u636e\u5feb\u7167&#xff0c;\u5f53\u6570\u636e\u5e93\u6570\u636e\u53d1\u751f\u53d8\u5316\u65f6\u4e0d\u4f1a\u81ea\u52a8\u66f4\u65b0\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u68c0\u7d22<\/span><\/p>\n<p><span style=\"color:#000000\">\u5f53\u5e94\u7528\u7a0b\u5e8f\u4e0b\u6b21\u9700\u8981\u6267\u884c\u76f8\u540c\u67e5\u8be2\u65f6&#xff0c;\u4f1a\u9996\u5148\u68c0\u67e5\u7f13\u5b58\u3002\u00a0\u5982\u679c\u7f13\u5b58\u4e2d\u5b58\u5728\u8be5\u67e5\u8be2\u7684\u6761\u76ee&#xff08;\u7f13\u5b58\u547d\u4e2d&#xff09;&#xff0c;\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u76f4\u63a5\u8fd4\u56de\u7f13\u5b58\u7ed3\u679c&#xff0c;\u800c\u65e0\u9700\u518d\u6b21\u67e5\u8be2\u6570\u636e\u5e93\u3002\u00a0\u8fd9\u663e\u8457\u964d\u4f4e\u4e86\u6570\u636e\u5e93\u8d1f\u8f7d&#xff0c;\u5e76\u63d0\u5347\u4e86\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd&#xff0c;\u56e0\u4e3a\u4ece\u7f13\u5b58\u8bfb\u53d6\u901a\u5e38\u6bd4\u6267\u884c\u6570\u636e\u5e93\u67e5\u8be2\u66f4\u5feb\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u5931\u6548<\/span><\/p>\n<p><span style=\"color:#000000\">\u5f53\u6570\u636e\u5e93\u4e2d\u4e0e\u7f13\u5b58\u67e5\u8be2\u5bf9\u5e94\u7684\u6570\u636e\u88ab\u66f4\u65b0\u65f6&#xff0c;\u76f8\u5e94\u7684\u7f13\u5b58\u6761\u76ee\u5c31\u4f1a\u8fc7\u65f6\u6216&#034;\u5931\u6548&#034;\u3002\u00a0\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u5236\u5b9a\u7b56\u7565\u6765\u5904\u7406\u8fd9\u4e9b\u60c5\u51b5\u3002\u00a0\u53ef\u4ee5\u9009\u62e9\u4f7f\u5931\u6548\u7684\u7f13\u5b58\u6761\u76ee\u65e0\u6548&#xff08;\u4ece\u7f13\u5b58\u4e2d\u79fb\u9664&#xff09;&#xff0c;\u6216\u8005\u7528\u65b0\u6570\u636e\u66f4\u65b0\u7f13\u5b58\u6761\u76ee\u3002\u00a0\u8fd9\u4e00\u6b65\u81f3\u5173\u91cd\u8981&#xff0c;\u56e0\u4e3a\u5982\u679c\u5904\u7406\u4e0d\u5f53&#xff0c;\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u7ee7\u7eed\u4f7f\u7528\u8fc7\u65f6\u6570\u636e&#xff0c;\u4ece\u800c\u5bfc\u81f4\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4f8b\u5982&#xff0c;\u6211\u4eec\u8003\u8651\u4e00\u4e2a\u4f7f\u7528 MongoDB \u6570\u636e\u5e93\u7684\u535a\u5ba2\u5e94\u7528\u3002\u00a0\u8be5\u5e94\u7528\u9700\u8981\u9891\u7e41\u83b7\u53d6\u6240\u6709\u535a\u5ba2\u6587\u7ae0\u7684\u5217\u8868\u4ee5\u663e\u793a\u5728\u9996\u9875\u4e0a\u3002\u00a0\u4e0e\u5176\u6bcf\u6b21\u6267\u884c\u76f8\u540c\u7684\u9ad8\u6210\u672c\u6570\u636e\u5e93\u67e5\u8be2&#xff0c;\u5e94\u7528\u53ef\u4ee5\u5c06\u7ed3\u679c\u7f13\u5b58\u8d77\u6765\u3002\u00a0\u5f53\u7528\u6237\u8bbf\u95ee\u9996\u9875\u65f6&#xff0c;\u5e94\u7528\u9996\u5148\u68c0\u67e5\u7f13\u5b58\u3002\u00a0\u5982\u679c\u6570\u636e\u5b58\u5728&#xff08;\u7f13\u5b58\u547d\u4e2d&#xff09;&#xff0c;\u5e94\u7528\u5c31\u76f4\u63a5\u63d0\u4f9b\u7f13\u5b58\u6570\u636e&#xff0c;\u4ece\u800c\u964d\u4f4e\u6570\u636e\u5e93\u8d1f\u8f7d\u5e76\u63d0\u9ad8\u54cd\u5e94\u901f\u5ea6\u3002\u00a0\u7136\u800c&#xff0c;\u5f53\u65b0\u589e\u535a\u5ba2\u6587\u7ae0\u65f6&#xff0c;\u7f13\u5b58\u7684\u6587\u7ae0\u5217\u8868\u5c31\u4f1a\u8fc7\u65f6\u3002\u00a0\u5e94\u7528\u9700\u8981\u5904\u7406\u8fd9\u4e00\u4e8b\u4ef6\u5e76\u76f8\u5e94\u5730\u66f4\u65b0\u6216\u4f7f\u7f13\u5b58\u5931\u6548\u3002\u00a0\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6570\u636e\u5e93\u89e6\u53d1\u5668\u6216\u91c7\u7528\u4e8b\u4ef6\u9a71\u52a8\u67b6\u6784\u6765\u5b9e\u73b0\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u7ba1\u7406\u540c\u6837\u662f\u5b9e\u73b0\u6570\u636e\u5e93\u7f13\u5b58\u7684\u5173\u952e\u73af\u8282&#xff0c;\u5305\u62ec\u8bbe\u7f6e\u5408\u9002\u7684\u7f13\u5b58\u5927\u5c0f\u3001\u5236\u5b9a\u7f13\u5b58\u6ee1\u8f7d\u65f6\u7684\u6dd8\u6c70\u7b56\u7565&#xff08;\u5982 LRU \u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7b97\u6cd5&#xff09;\u3001\u5904\u7406\u7f13\u5b58\u672a\u547d\u4e2d&#xff08;\u5f53\u8bf7\u6c42\u6570\u636e\u4e0d\u5728\u7f13\u5b58\u4e2d\u65f6&#xff09;\u4ee5\u53ca\u4e3a\u7f13\u5b58\u6761\u76ee\u8bbe\u7f6e\u5408\u7406\u7684\u5b58\u6d3b\u65f6\u95f4&#xff08;TTL&#xff09;\u3002<\/span><\/p>\n<h2 id=\"aid_154\" style=\"text-align:justify\"><span style=\"color:#000000\">\u5b9e\u73b0\u6570\u636e\u5e93\u7f13\u5b58<\/span><\/h2>\n<p><span style=\"color:#000000\">\u4f7f\u7528 MongoDB \u5b9e\u73b0\u6570\u636e\u5e93\u7f13\u5b58\u9700\u8981\u5728\u5e94\u7528\u7a0b\u5e8f\u548c MongoDB \u6570\u636e\u5e93\u4e4b\u95f4\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u62bd\u8c61\u5c42\u3002\u00a0\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Redis\u2014\u2014\u4e00\u4e2a\u975e\u5e38\u9002\u5408\u7f13\u5b58\u9700\u6c42\u7684\u9ad8\u6027\u80fd\u5185\u5b58\u6570\u636e\u7ed3\u6784\u5b58\u50a8\u2014\u2014\u6765\u6ee1\u8db3\u6211\u4eec\u7684\u7f13\u5b58\u9700\u6c42\u3002Redis \u662f\u4e13\u95e8\u4e3a\u7f13\u5b58\u800c\u8bbe\u8ba1\u7684\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7531\u4e8e\u8fd9\u90e8\u5206\u901a\u5e38\u662f\u535a\u5ba2\u4e2d\u6700\u53d7\u8bfb\u8005\u5173\u6ce8\u7684\u90e8\u5206&#xff0c;\u6211\u4eec\u5c06\u91cd\u70b9\u653e\u5728\u8d1f\u8d23\u83b7\u53d6\u535a\u5ba2\u6587\u7ae0\u7684\u535a\u5ba2\u5e94\u7528\u529f\u80fd\u4e0a\u3002\u00a0\u4ee5\u4e0b\u662f\u6211\u4eec\u5982\u4f55\u4fee\u6539\u6b64\u529f\u80fd\u4ee5\u5305\u542b\u7f13\u5b58\u7684\u7b80\u5316\u793a\u4f8b\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a fetchPosts()\u7684\u51fd\u6570&#xff0c;\u5b83\u4ece MongoDB \u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6240\u6709\u535a\u5ba2\u6587\u7ae0&#xff1a;<\/span><\/p>\n<p>std::vector&lt;Post&gt; fetchPosts(mongocxx::collection&amp; postCollection) {<br \/>\n   std::vector&lt;Post&gt; posts;<br \/>\n   auto cursor &#061; postCollection.find({});<br \/>\n   for(auto&amp;&amp; doc : cursor) {<br \/>\n       Post post;<br \/>\n       \/\/ Assume that fillPostFromDoc() fills a Post object from a BSON document.<br \/>\n       fillPostFromDoc(post, doc);<br \/>\n       posts.push_back(post);<br \/>\n   }<br \/>\n   return posts;<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u5c06\u4f7f\u7528 Redis \u4e3a\u8be5\u51fd\u6570\u6dfb\u52a0\u7f13\u5b58\u529f\u80fd\u3002\u00a0\u8bf7\u6ce8\u610f&#xff0c;\u4e0a\u8ff0\u793a\u4f8b\u7a0b\u5e8f\u5047\u8bbe\u60a8\u5df2\u8fd0\u884c Redis \u5b9e\u4f8b\u5e76\u5efa\u7acb\u4e86\u8fde\u63a5\u3002\u00a0\u6211\u4eec\u5c06\u4f7f\u7528 cpp_redis \u5e93\u6765\u5b9e\u73b0 C&#043;&#043;\u4e0e Redis \u7684\u4ea4\u4e92\u3002<\/span><\/p>\n<p>#include &lt;cpp_redis\/cpp_redis&gt;<br \/>\n\/\/ Assume that redisClient is a connected cpp_redis::client instance.<br \/>\nstd::vector&lt;Post&gt; fetchPosts(mongocxx::collection&amp; postCollection) {<br \/>\n   std::vector&lt;Post&gt; posts;<br \/>\n   std::string cacheKey &#061; &#034;posts&#034;;<br \/>\n   cpp_redis::reply redisReply &#061; redisClient.get(cacheKey);<br \/>\n   redisClient.sync_commit();<br \/>\n    \/\/ Cache miss: key doesn&#039;t exist in Redis.<br \/>\n   if(redisReply.is_null()) {<br \/>\n       \/\/ Fetch posts from MongoDB.<br \/>\n       auto cursor &#061; postCollection.find({});<br \/>\n       for(auto&amp;&amp; doc : cursor) {<br \/>\n           Post post;<br \/>\n           fillPostFromDoc(post, doc);<br \/>\n           posts.push_back(post);<br \/>\n       }<br \/>\n        \/\/ Cache the result in Redis. Assume that postsToJson() converts a vector of Post objects to a JSON string.<br \/>\n        \/\/ The third argument is the TTL (time-to-live) of the cache entry, after which it&#039;ll be automatically deleted.<br \/>\n       \/\/ Here it&#039;s set to 60 seconds.<br \/>\n       redisClient.set(cacheKey, postsToJson(posts), 60);<br \/>\n       redisClient.sync_commit();<br \/>\n   }<br \/>\n    \/\/ Cache hit: key exists in Redis.<br \/>\n   else {<br \/>\n       \/\/ Assume that jsonToPosts() converts a JSON string to a vector of Post objects.<br \/>\n       posts &#061; jsonToPosts(redisReply.as_string());<br \/>\n   }<br \/>\n   return posts;<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u5fc5\u987b\u7262\u8bb0&#xff0c;\u5f53\u535a\u5ba2\u6587\u7ae0\u88ab\u6dfb\u52a0\u3001\u66f4\u65b0\u6216\u5220\u9664\u65f6&#xff0c;\u6211\u4eec\u9700\u8981\u66f4\u65b0\u6216\u4f7f\u7f13\u5b58\u5931\u6548\u3002\u00a0\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u76f8\u5e94\u51fd\u6570\u6765\u5b9e\u73b0&#xff0c;\u540c\u65f6\u66f4\u65b0\u6216\u5220\u9664 Redis \u4e2d\u7684 posts \u952e\u3002<\/span><\/p>\n<p>void addPost(mongocxx::collection&amp; postCollection, const Post&amp; post) {<br \/>\n   \/\/ Add post to MongoDB.<br \/>\n    postCollection.insert_one(postToDoc(post));  \/\/ Assume that postToDoc() converts a Post object to a BSON document.<br \/>\n   \/\/ Invalidate the cache.<br \/>\n   redisClient.del(std::vector&lt;std::string&gt;{&#034;posts&#034;});<br \/>\n   redisClient.sync_commit();<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u8fd9\u4e9b\u662f\u7b80\u5316\u793a\u4f8b&#xff0c;\u5b9e\u9645\u5e94\u7528\u9700\u8981\u66f4\u590d\u6742\u7684\u7f13\u5b58\u7ba1\u7406\u7b56\u7565\u3002\u00a0\u4f8b\u5982&#xff0c;\u60a8\u53ef\u80fd\u53ea\u60f3\u7f13\u5b58\u70ed\u95e8\u535a\u5ba2\u6587\u7ae0\u6216\u83b7\u53d6\u6210\u672c\u8f83\u9ad8\u7684\u6587\u7ae0&#xff0c;\u6216\u8005\u4f7f\u7528\u66f4\u667a\u80fd\u7684\u7f13\u5b58\u5931\u6548\u7b56\u7565\u6765\u5c3d\u53ef\u80fd\u4fdd\u6301\u7f13\u5b58\u7684\u65b0\u9c9c\u5ea6\u3002<\/span><\/p>\n<h2 id=\"aid_155\" style=\"text-align:justify\"><span style=\"color:#000000\">\u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565<\/span><\/h2>\n<p><span style=\"color:#000000\">\u91c7\u7528\u9ad8\u7ea7\u7f13\u5b58\u7b56\u7565\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u535a\u5ba2\u5e94\u7528\u7684\u6027\u80fd\u3002\u00a0\u7f13\u5b58\u7b56\u7565\u7684\u9009\u62e9\u53d6\u51b3\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u5177\u4f53\u9700\u6c42\u548c\u9650\u5236\u6761\u4ef6\u3002\u00a0\u8ba9\u6211\u4eec\u5728\u535a\u5ba2\u5e94\u7528\u4e2d\u5b9e\u65bd\u5176\u4e2d\u4e00\u79cd\u7b56\u7565\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u5355\u7bc7\u535a\u5ba2\u6587\u7ae0<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728\u524d\u9762\u7684\u793a\u4f8b\u4e2d&#xff0c;\u6211\u4eec\u7f13\u5b58\u4e86\u6574\u4e2a\u535a\u5ba2\u6587\u7ae0\u5217\u8868\u3002\u00a0\u4f46\u5982\u679c\u5355\u7bc7\u6587\u7ae0\u7684\u83b7\u53d6\u6210\u672c\u8f83\u9ad8&#xff0c;\u5355\u72ec\u7f13\u5b58\u5b83\u4eec\u53ef\u80fd\u66f4\u6709\u4f18\u52bf\u3002\u00a0\u7f13\u5b58\u952e\u53ef\u4ee5\u91c7\u7528 post:&lt;id&gt; \u7684\u5f62\u5f0f&#xff0c;\u5176\u4e2d&lt;id&gt; \u662f\u535a\u5ba2\u6587\u7ae0\u7684 ID\u3002<\/span><\/p>\n<p>\/\/ \u5047\u8bbe redisClient \u662f\u4e00\u4e2a\u5df2\u8fde\u63a5\u7684 cpp_redis::client \u5b9e\u4f8b\u3002<br \/>\nPost fetchPost(mongocxx::collection&amp; postCollection, const std::string&amp; postId) {<br \/>\n   Post post;<br \/>\n    std::string cacheKey &#061; &#034;post:&#034; &#043; postId;<br \/>\n   cpp_redis::reply redisReply &#061; redisClient.get(cacheKey);<br \/>\n   redisClient.sync_commit();<br \/>\n   if(redisReply.is_null()) {<br \/>\n       \/\/ Fetch post from MongoDB.<br \/>\n       bsoncxx::document::view_or_value filter &#061; document{} &lt;&lt; &#034;_id&#034; &lt;&lt; bsoncxx::oid(postId) &lt;&lt; finalize;<br \/>\n       auto maybeResult &#061; postCollection.find_one(filter);<\/p>\n<p>       if(maybeResult) {<br \/>\n           fillPostFromDoc(post, maybeResult.value());<\/p>\n<p>           \/\/ Cache the post in Redis for 60 seconds.<br \/>\n           redisClient.set(cacheKey, postToJson(post), 60);<br \/>\n           redisClient.sync_commit();<br \/>\n       }<br \/>\n       else {<br \/>\n           \/\/ Handle the case when the post doesn&#039;t exist.<br \/>\n       }<br \/>\n   }<br \/>\n   else {<br \/>\n       post &#061; jsonToPost(redisReply.as_string());<br \/>\n   }<br \/>\n   return post;<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u65c1\u8def\u7f13\u5b58\/\u5ef6\u8fdf\u52a0\u8f7d<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728\u4e4b\u524d\u7684\u793a\u4f8b\u4e2d&#xff0c;\u6211\u4eec\u4e00\u76f4\u4f7f\u7528\u4e00\u79cd\u79f0\u4e3a&#034;\u65c1\u8def\u7f13\u5b58&#034;\u6216&#034;\u5ef6\u8fdf\u52a0\u8f7d&#034;\u7684\u7b56\u7565\u3002\u00a0\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ea\u5728\u6570\u636e\u88ab\u8bf7\u6c42\u4e14\u7f13\u5b58\u4e2d\u4e0d\u5b58\u5728\u65f6&#xff0c;\u624d\u4f1a\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u7f13\u5b58\u4e2d\u3002\u00a0\u5f53\u6570\u636e\u5e93\u8bfb\u53d6\u6210\u672c\u8f83\u9ad8\u4e14\u6570\u636e\u9700\u8981\u9891\u7e41\u8bfb\u53d6\u65f6&#xff0c;\u8fd9\u79cd\u65b9\u5f0f\u975e\u5e38\u6709\u6548\u3002\u00a0\u7136\u800c&#xff0c;\u5b83\u53ef\u80fd\u5bfc\u81f4\u7f13\u5b58\u672a\u547d\u4e2d\u65f6\u7684\u9ad8\u5ef6\u8fdf&#xff0c;\u56e0\u4e3a\u8bf7\u6c42\u5fc5\u987b\u76f4\u8fbe\u6570\u636e\u5e93\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u76f4\u5199\u5f0f\u7f13\u5b58<\/span><\/p>\n<p><span style=\"color:#000000\">\u76f4\u5199\u7b56\u7565\u786e\u4fdd\u7f13\u5b58\u4e0e\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u6570\u636e\u4e00\u81f4\u6027\u3002\u00a0\u5f53\u6570\u636e\u88ab\u5199\u5165\u65f6&#xff0c;\u5b83\u4f1a\u540c\u65f6\u5199\u5165\u7f13\u5b58\u548c\u6570\u636e\u5e93\u3002\u00a0\u7f13\u5b58\u59cb\u7ec8\u4e0e\u6570\u636e\u5e93\u4fdd\u6301\u540c\u6b65&#xff0c;\u8bfb\u53d6\u64cd\u4f5c\u5177\u6709\u4f4e\u5ef6\u8fdf&#xff0c;\u56e0\u4e3a\u5b83\u4eec\u603b\u662f\u547d\u4e2d\u7f13\u5b58\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5b9e\u73b0\u76f4\u5199\u7f13\u5b58\u9700\u8981\u4fee\u6539\u5199\u64cd\u4f5c&#xff08;\u5982 addPost()\u3001updatePost()\u548c deletePost()&#xff09;\u4ee5\u540c\u65f6\u66f4\u65b0\u7f13\u5b58\u3002<\/span><\/p>\n<p>void updatePost(mongocxx::collection&amp; postCollection, const Post&amp; post) {<br \/>\n   \/\/ Update post in MongoDB.<br \/>\n    bsoncxx::document::view_or_value filter &#061; document{} &lt;&lt; &#034;_id&#034; &lt;&lt; bsoncxx::oid(post.id) &lt;&lt; finalize;<br \/>\n    bsoncxx::document::view_or_value update &#061; document{} &lt;&lt; &#034;$set&#034; &lt;&lt; open_document &lt;&lt; &#034;title&#034; &lt;&lt; post.title &lt;&lt; &#034;body&#034; &lt;&lt; post.body &lt;&lt; close_document &lt;&lt; finalize;<br \/>\n   postCollection.update_one(filter, update);<br \/>\n   \/\/ Update cache.<br \/>\n    std::string cacheKey &#061; &#034;post:&#034; &#043; post.id;<br \/>\n   redisClient.set(cacheKey, postToJson(post));<br \/>\n   redisClient.sync_commit();<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u4ee5\u4e0b\u662f\u5b9e\u73b0\u5e94\u7528\u7f13\u5b58\u65f6\u53ef\u4ee5\u8003\u8651\u7684\u4e00\u4e9b\u7b56\u7565\u3002\u00a0\u6839\u636e\u60a8\u7684\u5177\u4f53\u9700\u6c42\u548c\u6570\u636e\u7279\u6027&#xff0c;\u60a8\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u4e0d\u540c\u7684\u7b56\u7565\u6216\u591a\u79cd\u7b56\u7565\u7684\u7ec4\u5408\u3002<\/span><\/p>\n<h2 id=\"aid_223\" style=\"text-align:justify\"><span style=\"color:#000000\">\u4f7f\u7528 gRPC \u63d0\u5347\u7f13\u5b58\u6027\u80fd<\/span><\/h2>\n<p><span style=\"color:#000000\">gRPC \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u3001\u5f00\u6e90\u3001\u901a\u7528\u7684 RPC \u6846\u67b6\u3002\u00a0\u5b83\u5728\u6539\u5584\u670d\u52a1\u5668\u7aef\u7f13\u5b58\u65b9\u9762\u80fd\u6210\u4e3a\u5f97\u529b\u5de5\u5177&#xff0c;\u539f\u56e0\u5982\u4e0b\u3002gRPC \u5141\u8bb8\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\u50cf\u8c03\u7528\u672c\u5730\u5bf9\u8c61\u4e00\u6837\u76f4\u63a5\u8c03\u7528\u670d\u52a1\u5668\u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5&#xff0c;\u4f7f\u5206\u5e03\u5f0f\u5e94\u7528\u548c\u670d\u52a1\u7684\u6784\u5efa\u66f4\u52a0\u4fbf\u6377\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"555\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250816032519-689ffa1fa3dbf.png\" width=\"525\" \/><\/p>\n<p><span style=\"color:#000000\">\u56fe 7.2 gRPC \u5de5\u4f5c\u539f\u7406<\/span><\/p>\n<p><span style=\"color:#000000\">\u8981\u5229\u7528 gRPC \u5b9e\u73b0\u670d\u52a1\u5668\u7aef\u7f13\u5b58&#xff0c;\u6211\u4eec\u9700\u8981\u5728.proto \u6587\u4ef6\u4e2d\u5b9a\u4e49\u670d\u52a1\u3002\u00a0\u8be5\u670d\u52a1\u5e94\u5305\u542b\u53ef\u7f13\u5b58\u6570\u636e\u83b7\u53d6\u65b9\u6cd5\u3002gRPC \u4f1a\u6839\u636e\u6211\u4eec\u7684\u670d\u52a1\u5b9a\u4e49\u81ea\u52a8\u751f\u6210\u4ee3\u7801\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5b9a\u4e49\u670d\u52a1<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728.proto \u6587\u4ef6\u4e2d\u5b9a\u4e49\u670d\u52a1&#xff1a;<\/span><\/p>\n<p>syntax &#061; &#034;proto3&#034;;<br \/>\nservice BlogService {<br \/>\n   rpc GetPost(GetPostRequest) returns (Post);<br \/>\n   rpc ListPosts(Empty) returns (PostList);<br \/>\n}<br \/>\nmessage GetPostRequest {<br \/>\n   string id &#061; 1;<br \/>\n}<br \/>\nmessage Post {<br \/>\n   string id &#061; 1;<br \/>\n   string title &#061; 2;<br \/>\n   string body &#061; 3;<br \/>\n}<br \/>\nmessage PostList {<br \/>\n   repeated Post posts &#061; 1;<br \/>\n}<br \/>\nmessage Empty {}<\/p>\n<p><span style=\"color:#000000\">\u6570\u636e\u83b7\u53d6<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728\u751f\u6210\u7684\u670d\u52a1\u5b9e\u73b0\u4e2d&#xff0c;\u83b7\u53d6\u6570\u636e\u65f6\u4f7f\u7528\u7f13\u5b58&#xff1a;<\/span><\/p>\n<p>class BlogServiceImpl final : public BlogService::Service {<br \/>\npublic:<br \/>\n    grpc::Status GetPost(grpc::ServerContext* context, const GetPostRequest* request, Post* response) override {<br \/>\n       \/\/ Fetch the post from cache or from MongoDB.<br \/>\n       Post post &#061; fetchPost(postCollection, request-&gt;id());<br \/>\n       \/\/ Fill the response with the fetched post.<br \/>\n       response-&gt;set_id(post.id);<br \/>\n       response-&gt;set_title(post.title);<br \/>\n       response-&gt;set_body(post.body);<br \/>\n       return grpc::Status::OK;<br \/>\n   }<br \/>\n    grpc::Status ListPosts(grpc::ServerContext* context, const Empty* request, PostList* response) override {<br \/>\n       \/\/ Fetch the list of posts from cache or from MongoDB.<br \/>\n       std::vector&lt;Post&gt; posts &#061; fetchPostList(postCollection);<br \/>\n       \/\/ Fill the response with the fetched posts.<br \/>\n       for(const Post&amp; post : posts) {<br \/>\n           Post* postInResponse &#061; response-&gt;add_posts();<br \/>\n           postInResponse-&gt;set_id(post.id);<br \/>\n           postInResponse-&gt;set_title(post.title);<br \/>\n           postInResponse-&gt;set_body(post.body);<br \/>\n       }<br \/>\n       return grpc::Status::OK;<br \/>\n   }<br \/>\n};<\/p>\n<p><span style=\"color:#000000\">\u5efa\u7acb gRPC \u670d\u52a1\u5668<\/span><\/p>\n<p><span style=\"color:#000000\">\u8bbe\u7f6e\u4e00\u4e2a\u4f7f\u7528\u670d\u52a1\u5b9e\u73b0\u7684 gRPC \u670d\u52a1\u5668&#xff1a;<\/span><\/p>\n<p>int main() {<br \/>\n   std::string serverAddress(&#034;0.0.0.0:50051&#034;);<br \/>\n   BlogServiceImpl service;<br \/>\n   grpc::ServerBuilder builder;<br \/>\n   builder.AddListeningPort(serverAddress, grpc::InsecureServerCredentials());<br \/>\n   builder.RegisterService(&amp;service);<br \/>\n   std::unique_ptr&lt;grpc::Server&gt; server(builder.BuildAndStart());<br \/>\n    std::cout &lt;&lt; &#034;Server listening on &#034; &lt;&lt; serverAddress &lt;&lt; std::endl;<br \/>\n   server-&gt;Wait();<br \/>\n   return 0;<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f&#xff0c;gRPC \u5e2e\u52a9\u62bd\u8c61\u4e86\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528\u7684\u590d\u6742\u6027&#xff0c;\u4f7f\u60a8\u80fd\u591f\u4e13\u6ce8\u4e8e\u5e94\u7528\u903b\u8f91\u672c\u8eab\u3002\u00a0\u901a\u8fc7\u4e3a\u5e94\u7528\u7a0b\u5e8f\u64cd\u4f5c\u5b9a\u4e49\u670d\u52a1&#xff0c;\u60a8\u53ef\u4ee5\u65e0\u7f1d\u96c6\u6210\u7f13\u5b58\u3001\u63d0\u5347\u6027\u80fd\u5e76\u6709\u6548\u6269\u5c55\u5e94\u7528\u3002gRPC \u4f7f\u7528 HTTP\/2 \u534f\u8bae&#xff0c;\u5176\u6027\u80fd\u6548\u7387\u8fdc\u9ad8\u4e8e HTTP\/1\u3002\u00a0\u8fd9\u662f\u56e0\u4e3a HTTP\/2 \u652f\u6301\u8bf7\u6c42\/\u54cd\u5e94\u591a\u8def\u590d\u7528&#xff0c;\u5141\u8bb8\u591a\u4e2a\u8bf7\u6c42\u548c\u54cd\u5e94\u540c\u65f6\u4f20\u8f93\u3002\u00a0\u5b83\u8fd8\u652f\u6301\u670d\u52a1\u5668\u63a8\u9001&#xff0c;\u53ef\u8fdb\u4e00\u6b65\u4f18\u5316\u7f13\u5b58\u673a\u5236\u3002<\/span><\/p>\n<h2 id=\"aid_140\" style=\"text-align:justify\"><span style=\"color:#000000\">\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565<\/span><\/h2>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u6dd8\u6c70\u662f\u9ad8\u901f\u7f13\u5b58\u5c42\u7ba1\u7406\u4e2d\u7684\u5173\u952e\u6d41\u7a0b&#xff0c;\u8be5\u5b58\u50a8\u5c42\u4fdd\u5b58\u7740\u7cfb\u7edf\u53ef\u80fd\u518d\u6b21\u4f7f\u7528\u7684\u6570\u636e\u3002\u00a0\u7f13\u5b58\u6dd8\u6c70\u7684\u4e3b\u8981\u76ee\u7684\u662f\u901a\u8fc7\u79fb\u9664\u90e8\u5206\u73b0\u6709\u6761\u76ee\u4e3a\u65b0\u6761\u76ee\u817e\u51fa\u7a7a\u95f4\u3002\u00a0\u5f53\u7f13\u5b58\u5df2\u6ee1\u4e14\u9700\u8981\u5bb9\u7eb3\u65b0\u6761\u76ee\u65f6&#xff0c;\u8fd9\u4e00\u8fc7\u7a0b\u5c31\u53d8\u5f97\u5fc5\u8981\u3002\u00a0\u51b3\u5b9a\u5e94\u79fb\u9664\u54ea\u4e2a\u73b0\u6709\u6761\u76ee\u7684\u65b9\u6cd5\u6216\u7b56\u7565\u88ab\u79f0\u4e3a\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\u3002\u00a0\u5b58\u5728\u591a\u79cd\u4e0d\u540c\u7684\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565&#xff0c;\u4f46\u5728\u672c\u6b21\u8ba8\u8bba\u4e2d&#xff0c;\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u4e09\u79cd\u6700\u5e38\u7528\u7684\u7b56\u7565&#xff1a;\u6700\u8fd1\u6700\u5c11\u4f7f\u7528(LRU)\u3001\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528(LFU)\u548c\u968f\u673a\u66ff\u6362(RR)\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u6700\u8fd1\u6700\u5c11\u4f7f\u7528(LRU)<\/span><\/p>\n<p><span style=\"color:#000000\">\u6700\u8fd1\u6700\u5c11\u4f7f\u7528&#xff08;LRU&#xff09;\u7b56\u7565\u662f\u6700\u6d41\u884c\u7684\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\u4e4b\u4e00\u3002\u00a0\u987e\u540d\u601d\u4e49&#xff0c;\u8be5\u7b56\u7565\u4f1a\u79fb\u9664\u6700\u957f\u65f6\u95f4\u672a\u88ab\u4f7f\u7528\u6216\u8bf7\u6c42\u7684\u6761\u76ee\u3002\u00a0\u5176\u57fa\u672c\u5047\u8bbe\u662f&#xff1a;\u5982\u679c\u4e00\u4e2a\u6761\u76ee\u957f\u65f6\u95f4\u672a\u88ab\u8bf7\u6c42&#xff0c;\u90a3\u4e48\u5b83\u5728\u8fd1\u671f\u88ab\u8bf7\u6c42\u7684\u53ef\u80fd\u6027\u8f83\u4f4e\u3002\u00a0\u4f8b\u5982&#xff0c;\u5728\u4e00\u4e2a\u535a\u5ba2\u5e94\u7528\u4e2d\u7f13\u5b58\u6700\u8fd1\u8bbf\u95ee\u7684\u535a\u5ba2\u6587\u7ae0\u65f6&#xff0c;\u5f53\u7f13\u5b58\u7a7a\u95f4\u4e0d\u8db3\u65f6&#xff0c;LRU \u7b56\u7565\u4f1a\u8981\u6c42\u6211\u4eec\u4e22\u5f03\u6700\u957f\u65f6\u95f4\u672a\u88ab\u8bbf\u95ee\u7684\u6587\u7ae0\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5b9e\u73b0 LRU \u7f13\u5b58\u53ef\u4ee5\u9ad8\u6548\u5730\u901a\u8fc7\u54c8\u5e0c\u8868\u4e0e\u53cc\u5411\u94fe\u8868\u7684\u7ec4\u5408\u6765\u5b8c\u6210\u3002\u00a0\u54c8\u5e0c\u8868\u63d0\u4f9b\u4e86\u5bf9\u7f13\u5b58\u7684\u5e38\u6570\u65f6\u95f4\u8bbf\u95ee&#xff0c;\u786e\u4fdd\u6570\u636e\u80fd\u88ab\u5feb\u901f\u68c0\u7d22\u3002\u00a0\u800c\u53cc\u5411\u94fe\u8868\u5219\u5141\u8bb8\u6211\u4eec\u5728\u5e38\u6570\u65f6\u95f4\u5185\u6dfb\u52a0\u6216\u79fb\u9664\u6761\u76ee&#xff0c;\u4f7f\u5176\u6210\u4e3a\u7ef4\u62a4\u57fa\u4e8e\u4f7f\u7528\u987a\u5e8f\u7684\u7406\u60f3\u6570\u636e\u7ed3\u6784\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528&#xff08;LFU&#xff09;<\/span><\/p>\n<p><span style=\"color:#000000\">\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528&#xff08;LFU&#xff09;\u7b56\u7565\u662f\u53e6\u4e00\u79cd\u5e38\u89c1\u7684\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\u3002\u00a0\u8be5\u7b56\u7565\u4f1a\u6dd8\u6c70\u88ab\u8bf7\u6c42\u9891\u7387\u6700\u4f4e\u7684\u7f13\u5b58\u9879\u3002\u00a0\u5176\u539f\u7406\u5728\u4e8e&#xff1a;\u5982\u679c\u67d0\u4e2a\u9879\u76ee\u5f88\u5c11\u88ab\u8bf7\u6c42&#xff0c;\u90a3\u4e48\u5b83\u8fd1\u671f\u518d\u6b21\u88ab\u8bf7\u6c42\u7684\u53ef\u80fd\u6027\u4e5f\u8f83\u4f4e\u3002\u00a0\u5b9e\u73b0 LFU \u7f13\u5b58\u53ef\u80fd\u6bd4 LRU \u66f4\u590d\u6742&#xff0c;\u4f46\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\u80fd\u83b7\u5f97\u66f4\u597d\u7684\u6548\u679c\u3002\u00a0\u5b83\u9700\u8981\u8bb0\u5f55\u8bbf\u95ee\u9891\u7387&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u54c8\u5e0c\u6620\u5c04\u6765\u5b58\u50a8\u7f13\u5b58\u9879&#xff0c;\u518d\u7528\u53e6\u4e00\u4e2a\u6765\u8bb0\u5f55\u8bbf\u95ee\u9891\u7387\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u968f\u673a\u66ff\u6362&#xff08;RR&#xff09;<\/span><\/p>\n<p><span style=\"color:#000000\">\u968f\u673a\u66ff\u6362&#xff08;RR&#xff09;\u662f\u4e00\u79cd\u4ee5\u7b80\u5355\u8457\u79f0\u7684\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\u3002\u00a0\u5f53\u7f13\u5b58\u5df2\u6ee1\u65f6&#xff0c;\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u6761\u76ee\u8fdb\u884c\u6dd8\u6c70&#xff0c;\u4e3a\u65b0\u6761\u76ee\u817e\u51fa\u7a7a\u95f4\u3002\u00a0\u8fd9\u79cd\u65b9\u6cd5\u5b9e\u73b0\u7b80\u5355&#xff0c;\u4f46\u5b8c\u5168\u4e0d\u8003\u8651\u4f7f\u7528\u6a21\u5f0f&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u9891\u7e41\u8bbf\u95ee\u7684\u91cd\u8981\u9879\u76ee\u88ab\u610f\u5916\u6dd8\u6c70\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\u5728\u4f18\u5316\u7f13\u5b58\u7a7a\u95f4\u4f7f\u7528\u65b9\u9762\u8d77\u7740\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002\u00a0\u901a\u8fc7\u786e\u4fdd\u7f13\u5b58\u4e2d\u4fdd\u5b58\u6700\u76f8\u5173\u7684\u6570\u636e&#xff0c;\u8fd9\u4e9b\u7b56\u7565\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u540e\u7aef\u5e94\u7528\u7684\u6548\u7387\u548c\u6027\u80fd\u3002\u00a0\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u6700\u4f73\u7b56\u7565\u7684\u9009\u62e9\u901a\u5e38\u53d6\u51b3\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u5177\u4f53\u8bbf\u95ee\u6a21\u5f0f\u3002\u00a0\u4f8b\u5982&#xff0c;\u535a\u5ba2\u7f51\u7ad9\u53ef\u80fd\u66f4\u9002\u5408\u91c7\u7528 LRU \u6216 LFU \u7b56\u7565&#xff0c;\u56e0\u4e3a\u67d0\u4e9b\u535a\u6587\u5f88\u53ef\u80fd\u6bd4\u5176\u4ed6\u5185\u5bb9\u88ab\u66f4\u9891\u7e41\u5730\u8bbf\u95ee\u3002\u00a0\u800c\u5bf9\u4e8e\u8bbf\u95ee\u6a21\u5f0f\u66f4\u96be\u9884\u6d4b\u7684\u5e94\u7528\u7a0b\u5e8f&#xff0c;RR \u7b56\u7565\u53ef\u80fd\u662f\u66f4\u597d\u7684\u9009\u62e9\u3002\u00a0\u56e0\u6b64&#xff0c;\u7406\u89e3\u5e94\u7528\u7a0b\u5e8f\u7279\u6027\u53ca\u5176\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f\u662f\u9009\u62e9\u6700\u6709\u6548\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\u7684\u5173\u952e\u3002<\/span><\/p>\n<h2 id=\"aid_243\" style=\"text-align:justify\"><span style=\"color:#000000\">LRU \u5b9e\u73b0\u65b9\u6848<\/span><\/h2>\n<p><span style=\"color:#000000\">\u6700\u8fd1\u6700\u5c11\u4f7f\u7528(LRU)\u7f13\u5b58\u7b56\u7565\u7684\u5b9e\u73b0\u5305\u542b\u4e24\u4e2a\u4e3b\u8981\u7ec4\u4ef6&#xff1a;\u7528\u4e8e\u5e38\u91cf\u65f6\u95f4\u6570\u636e\u8bbf\u95ee\u7684\u54c8\u5e0c\u8868&#xff0c;\u4ee5\u53ca\u7528\u4e8e\u5e38\u91cf\u65f6\u95f4\u6570\u636e\u6dfb\u52a0\u548c\u5220\u9664\u7684\u53cc\u5411\u94fe\u8868\u3002\u00a0\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d&#xff0c;\u6211\u4eec\u5c06\u4f7f\u7528 C&#043;&#043;\u6807\u51c6\u6a21\u677f\u5e93\u4e3a\u5047\u8bbe\u7684\u535a\u5ba2\u5e94\u7528\u5b9e\u73b0\u4e00\u4e2a LRU \u7f13\u5b58&#xff1a;<\/span><\/p>\n<p>#include &lt;unordered_map&gt;<br \/>\n#include &lt;list&gt;<br \/>\n#include &lt;iostream&gt;<br \/>\n\/\/ Implementing an LRU Cache using C&#043;&#043; STL<br \/>\nclass LRUCache {<br \/>\npublic:<br \/>\n   LRUCache(int capacity): size(capacity) {}<br \/>\n   int get(int key) {<br \/>\n       if(cache.find(key) &#061;&#061; cache.end()) return -1;<br \/>\n       moveToFront(key);<br \/>\n       return cache[key].second;<br \/>\n   }<br \/>\n    void put(int key, int value) {<br \/>\n       if(cache.find(key) !&#061; cache.end())<br \/>\n           removeKey(key);<br \/>\n       else if(cache.size() &#061;&#061; size)<br \/>\n           removeKey(lru.back());<br \/>\n       addToFront(key, value);<br \/>\n   }<br \/>\nprivate:<br \/>\n   typedef std::pair&lt;int, int&gt; Pair;<br \/>\n   typedef std::list&lt;int&gt;::iterator ListIterator;<br \/>\n   std::unordered_map&lt;int, std::pair&lt;int, ListIterator&gt;&gt; cache;<br \/>\n   std::list&lt;int&gt; lru;<br \/>\n   int size;<br \/>\n    void addToFront(int key, int value) {<br \/>\n       lru.push_front(key);<br \/>\n       cache[key] &#061; {value, lru.begin()};<br \/>\n   }<br \/>\n   void removeKey(int key) {<br \/>\n       lru.erase(cache[key].second);<br \/>\n       cache.erase(key);<br \/>\n   }<br \/>\n   void moveToFront(int key) {<br \/>\n       lru.erase(cache[key].second);<br \/>\n       lru.push_front(key);<br \/>\n       cache[key].second &#061; lru.begin();<br \/>\n   }<br \/>\n};<\/p>\n<p><span style=\"color:#000000\">\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d&#xff0c;\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a LRUCache \u7684\u7c7b\u6765\u5b9e\u73b0\u6700\u8fd1\u6700\u5c11\u4f7f\u7528(LRU)\u7f13\u5b58\u3002LRUCache \u7c7b\u5305\u542b\u4e24\u4e2a\u79c1\u6709\u6210\u5458&#xff1a;\u4e00\u4e2a\u540d\u4e3a cache \u7684\u54c8\u5e0c\u6620\u5c04\u548c\u4e00\u4e2a\u540d\u4e3a lru \u7684\u53cc\u5411\u94fe\u8868\u3002\u00a0\u54c8\u5e0c\u6620\u5c04 cache \u7528\u4e8e\u5b58\u50a8\u7f13\u5b58\u7684\u952e\u503c\u5bf9\u3002\u00a0\u952e\u662f\u6570\u636e\u7684\u552f\u4e00\u6807\u8bc6\u7b26&#xff0c;\u503c\u662f\u5b9e\u9645\u6570\u636e\u3002\u00a0\u54c8\u5e0c\u6620\u5c04\u5141\u8bb8\u6211\u4eec\u5728\u7ed9\u5b9a\u952e\u7684\u60c5\u51b5\u4e0b\u4ee5\u6052\u5b9a\u65f6\u95f4\u8bbf\u95ee\u4efb\u4f55\u503c&#xff0c;\u4f7f\u5176\u6210\u4e3a\u5b9e\u73b0\u6b64\u76ee\u7684\u7684\u9ad8\u6548\u6570\u636e\u7ed3\u6784\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u53cc\u5411\u94fe\u8868 lru \u7528\u4e8e\u8bb0\u5f55\u952e\u7684\u4f7f\u7528\u987a\u5e8f\u3002\u00a0\u6700\u8fd1\u4f7f\u7528\u7684\u952e\u4f4d\u4e8e\u94fe\u8868\u524d\u7aef&#xff0c;\u800c\u6700\u4e45\u672a\u4f7f\u7528\u7684\u952e\u4f4d\u4e8e\u94fe\u8868\u672b\u7aef\u3002\u00a0\u5f53\u7f13\u5b58\u5df2\u6ee1\u4e14\u9700\u8981\u6dfb\u52a0\u65b0\u952e\u503c\u5bf9\u65f6&#xff0c;\u8be5\u94fe\u8868\u80fd\u8ba9\u6211\u4eec\u5feb\u901f\u5b9a\u4f4d\u5e76\u79fb\u9664\u6700\u4e45\u672a\u4f7f\u7528\u7684\u952e\u3002LRUCache \u7c7b\u5305\u542b\u4e00\u4e2a get()\u51fd\u6570&#xff0c;\u7528\u4e8e\u68c0\u67e5\u952e\u662f\u5426\u5b58\u5728\u4e8e\u7f13\u5b58\u4e2d\u3002\u00a0\u82e5\u952e\u5b58\u5728&#xff0c;\u8be5\u51fd\u6570\u4f1a\u5c06\u5176\u79fb\u81f3 lru \u94fe\u8868\u524d\u7aef&#xff0c;\u6807\u8bb0\u4e3a\u6700\u8fd1\u4f7f\u7528\u7684\u952e\u3002\u00a0\u968f\u540e\u8fd4\u56de\u4e0e\u8be5\u952e\u5173\u8054\u7684\u503c\u3002\u00a0\u82e5\u952e\u4e0d\u5b58\u5728\u4e8e\u7f13\u5b58\u4e2d&#xff0c;\u5219\u51fd\u6570\u8fd4\u56de\u9884\u5b9a\u4e49\u7684\u7f13\u5b58\u672a\u547d\u4e2d\u503c\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">put()\u51fd\u6570\u7528\u4e8e\u5411\u7f13\u5b58\u4e2d\u6dfb\u52a0\u65b0\u7684\u952e\u503c\u5bf9\u3002\u00a0\u5982\u679c\u8be5\u952e\u5df2\u5b58\u5728\u4e8e\u7f13\u5b58\u4e2d&#xff0c;\u51fd\u6570\u4f1a\u5148\u79fb\u9664\u65e7\u7684\u952e\u503c\u5bf9\u518d\u6dfb\u52a0\u65b0\u503c\u3002\u00a0\u8fd9\u786e\u4fdd\u4e86\u7f13\u5b58\u4e2d\u59cb\u7ec8\u4fdd\u5b58\u7740\u6307\u5b9a\u952e\u7684\u6700\u65b0\u503c\u3002\u00a0\u5f53\u7f13\u5b58\u8fbe\u5230\u5bb9\u91cf\u4e0a\u9650\u65f6&#xff0c;\u51fd\u6570\u4f1a\u5148\u79fb\u9664\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7684\u952e\u503c\u5bf9&#xff0c;\u518d\u6dfb\u52a0\u65b0\u6761\u76ee\u3002\u00a0\u8fd9\u6b63\u662f LRU&#xff08;\u6700\u8fd1\u6700\u5c11\u4f7f\u7528&#xff09;\u7b56\u7565\u7684\u5e94\u7528\u573a\u666f\u3002moveToFront()\u3001removeKey()\u548c addToFront()\u662f\u8f85\u52a9\u51fd\u6570&#xff0c;\u7528\u4e8e\u7ef4\u62a4 lru \u94fe\u8868\u548c\u7f13\u5b58\u54c8\u5e0c\u8868\u3002moveToFront()\u51fd\u6570\u5c06\u6307\u5b9a\u952e\u79fb\u52a8\u5230 lru \u94fe\u8868\u7684\u6700\u524d\u7aef\u3002removeKey()\u51fd\u6570\u4f1a\u4ece\u7f13\u5b58\u548c lru \u94fe\u8868\u4e2d\u540c\u65f6\u79fb\u9664\u6307\u5b9a\u952e\u3002addToFront()\u51fd\u6570\u5219\u5c06\u65b0\u952e\u6dfb\u52a0\u5230 lru \u94fe\u8868\u524d\u7aef&#xff0c;\u5e76\u5c06\u5176\u5173\u8054\u503c\u5b58\u5165\u7f13\u5b58\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u6709\u8da3\u7684 LRU \u7f13\u5b58\u65b9\u6848\u3002\u00a0\u5176 get \u548c put \u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a O(1)&#xff0c;\u8fd9\u610f\u5473\u7740\u65e0\u8bba\u7f13\u5b58\u89c4\u6a21\u5982\u4f55&#xff0c;\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u80fd\u5728\u6052\u5b9a\u65f6\u95f4\u5185\u5b8c\u6210\u3002\u00a0\u8fd9\u79cd LRU \u7f13\u5b58\u8bbe\u8ba1\u6a21\u5f0f\u975e\u5e38\u9002\u5408\u8d44\u6e90\u6709\u9650\u4e14\u6548\u7387\u81f3\u5173\u91cd\u8981\u7684\u73b0\u5b9e\u573a\u666f&#xff0c;\u4f8b\u5982\u6570\u636e\u5e93\u67e5\u8be2\u3001\u7f51\u9875\u7f13\u5b58\u4ee5\u53ca\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u5185\u5b58\u7ba1\u7406\u7b49\u5e94\u7528\u573a\u666f\u3002<\/span><\/p>\n<h2 id=\"aid_69\" style=\"text-align:justify\"><span style=\"color:#000000\">LFU \u5b9e\u73b0<\/span><\/h2>\n<p><span style=\"color:#000000\">\u5b9e\u73b0\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528&#xff08;LFU&#xff09;\u7f13\u5b58\u7b56\u7565\u6bd4 LRU \u7a0d\u590d\u6742&#xff0c;\u56e0\u4e3a\u5b83\u9700\u8981\u8ddf\u8e2a\u6570\u636e\u7684\u8bbf\u95ee\u9891\u7387\u3002\u00a0\u8ba9\u6211\u4eec\u8003\u8651\u4f7f\u7528 C&#043;&#043;\u6807\u51c6\u5e93&#xff08;STL&#xff09;\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684 LFU \u7f13\u5b58&#xff1a;<\/span><\/p>\n<p>#include &lt;unordered_map&gt;<br \/>\n#include &lt;list&gt;<br \/>\n#include &lt;iostream&gt;<br \/>\nclass LFUCache {<br \/>\n   int cap, size, minFreq;<br \/>\n    std::unordered_map&lt;int, std::pair&lt;int, int&gt;&gt; m; \/\/Key to {value,freq};<br \/>\n    std::unordered_map&lt;int, std::list&lt;std::list&lt;int&gt;::iterator&gt;&gt; freq; \/\/Freq to key list;<br \/>\n    std::unordered_map&lt;int, std::list&lt;int&gt;&gt; l; \/\/key to iterator;<br \/>\npublic:<br \/>\n   LFUCache(int capacity) {<br \/>\n       cap &#061; capacity;<br \/>\n       size &#061; 0;<br \/>\n   }<\/p>\n<p>   int get(int key) {<br \/>\n       if(m.find(key) !&#061; m.end()) {<br \/>\n           freq[m[key].second].erase(l[key]);<br \/>\n           if(freq[m[key].second].empty()) freq.erase(m[key].second);<br \/>\n           &#043;&#043;m[key].second;<br \/>\n           freq[m[key].second].push_back(key);<br \/>\n           l[key] &#061; &#8211;freq[m[key].second].end();<br \/>\n           if(minFreq &#061;&#061; m[key].second &#8211; 1 &amp;&amp; freq.find(minFreq) &#061;&#061; freq.end())<br \/>\n               &#043;&#043;minFreq;<br \/>\n           return m[key].first;<br \/>\n       }<br \/>\n       return -1;<br \/>\n   }<\/p>\n<p>    void put(int key, int value) {<br \/>\n       if(cap &lt;&#061; 0) return;<br \/>\n       int storedValue &#061; get(key);<br \/>\n       if(storedValue !&#061; -1) {<br \/>\n           m[key].first &#061; value;<br \/>\n           return;<br \/>\n       }<br \/>\n       if(size &gt;&#061; cap ) {<br \/>\n           m.erase(freq[minFreq].front());<br \/>\n           l.erase(freq[minFreq].front());<br \/>\n           freq[minFreq].pop_front();<br \/>\n           if(freq[minFreq].size() &#061;&#061; 0) freq.erase(minFreq);<br \/>\n           &#8211;size;<br \/>\n       }<br \/>\n       m[key] &#061; {value, 1};<br \/>\n       freq[1].push_back(key);<br \/>\n       l[key] &#061; &#8211;freq[1].end();<br \/>\n       minFreq &#061; 1;<br \/>\n       &#043;&#043;size;<br \/>\n   }<br \/>\n};<\/p>\n<p><span style=\"color:#000000\">get \u548c put \u51fd\u6570\u4e0e LRU \u7f13\u5b58\u4e2d\u7684\u529f\u80fd\u975e\u5e38\u76f8\u4f3c\u3002\u00a0\u4f46\u5b83\u4eec\u8fd8\u4f1a\u8c03\u6574\u5143\u7d20\u7684\u8bbf\u95ee\u9891\u7387\u3002\u00a0\u5728\u672c\u5b9e\u73b0\u4e2d&#xff0c;\u6211\u4eec\u4f7f\u7528\u4e86\u4e09\u79cd\u6570\u636e\u7ed3\u6784\u3002m \u7528\u4e8e\u8bb0\u5f55\u952e\u5230{\u503c&#xff0c;\u9891\u7387}\u7684\u6620\u5c04\u3002freq \u662f\u4e00\u4e2a\u4ece\u9891\u7387\u5230\u5177\u6709\u8be5\u9891\u7387\u7684\u952e\u5217\u8868\u7684\u6620\u5c04\u3002\u00a0\u6700\u540e&#xff0c;l \u7528\u4e8e\u8ffd\u8e2a\u6307\u5411\u952e\u5728\u5217\u8868\u4e2d\u4f4d\u7f6e\u7684\u8fed\u4ee3\u5668\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">get \u51fd\u6570\u4f1a\u589e\u52a0\u88ab\u8bbf\u95ee\u952e\u7684\u9891\u7387&#xff0c;\u5e76\u8c03\u6574\u8be5\u952e\u5728 freq \u6620\u5c04\u4e2d\u7684\u4f4d\u7f6e\u3002put \u51fd\u6570\u9996\u5148\u901a\u8fc7 get \u51fd\u6570\u68c0\u67e5\u952e\u662f\u5426\u5df2\u5728\u7f13\u5b58\u4e2d\u3002\u00a0\u5982\u679c\u952e\u4e0d\u5728\u7f13\u5b58\u4e2d\u4e14\u7f13\u5b58\u5927\u5c0f\u5c0f\u4e8e\u5bb9\u91cf&#xff0c;\u5219\u6dfb\u52a0\u952e\u503c\u5bf9&#xff1b;\u5426\u5219\u5728\u6dfb\u52a0\u65b0\u952e\u503c\u5bf9\u524d\u79fb\u9664\u6700\u4e0d\u5e38\u4f7f\u7528\u7684\u952e\u503c\u5bf9\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8be5 LFU \u7f13\u5b58\u5b9e\u73b0\u786e\u4fdd\u5f53\u7f13\u5b58\u5df2\u6ee1\u4e14\u9700\u8981\u63d2\u5165\u65b0\u6570\u636e\u70b9\u65f6&#xff0c;\u4f1a\u79fb\u9664\u4f7f\u7528\u9891\u7387\u6700\u4f4e\u7684\u6570\u636e\u3002\u00a0\u8fd9\u79cd\u6a21\u5f0f\u9002\u7528\u4e8e\u67d0\u4e9b\u7279\u5b9a\u7c7b\u578b\u7684\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f&#xff0c;\u5176\u4e2d\u8bbf\u95ee\u9891\u7387\u80fd\u6709\u6548\u9884\u6d4b\u672a\u6765\u7684\u8bbf\u95ee\u60c5\u51b5\u3002<\/span><\/p>\n<h2 id=\"aid_67\" style=\"text-align:justify\"><span style=\"color:#000000\">RR \u5b9e\u73b0\u65b9\u6848<\/span><\/h2>\n<p><span style=\"color:#000000\">\u968f\u673a\u66ff\u6362(RR)\u662f\u4e00\u79cd\u901a\u8fc7\u968f\u673a\u9009\u62e9\u5019\u9009\u9879\u76ee\u8fdb\u884c\u66ff\u6362\u7684\u7f13\u5b58\u7b97\u6cd5\u3002\u00a0\u8be5\u7b97\u6cd5\u975e\u5e38\u7b80\u5355\u9ad8\u6548&#xff0c;\u56e0\u4e3a\u5b83\u4e0d\u9700\u8981\u7ef4\u62a4\u4efb\u4f55\u5173\u4e8e\u9879\u76ee\u4f7f\u7528\u9891\u7387\u6216\u6700\u8fd1\u4f7f\u7528\u60c5\u51b5\u7684\u989d\u5916\u4fe1\u606f\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4ee5\u4e0b\u662f C&#043;&#043;\u5b9e\u73b0\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;unordered_map&gt;<br \/>\n#include &lt;cstdlib&gt;<br \/>\nclass RRCache {<br \/>\nprivate:<br \/>\n   int capacity;<br \/>\n   std::vector&lt;int&gt; keys;<br \/>\n   std::unordered_map&lt;int, int&gt; cache;<br \/>\npublic:<br \/>\n   RRCache(int capacity) {<br \/>\n       this-&gt;capacity &#061; capacity;<br \/>\n   }<br \/>\n   int get(int key) {<br \/>\n       if(cache.find(key) !&#061; cache.end()) {<br \/>\n           return cache[key];<br \/>\n       } else {<br \/>\n           return -1;<br \/>\n       }<br \/>\n   }<br \/>\n    void put(int key, int value) {<br \/>\n       if(cache.size() &#061;&#061; capacity) {<br \/>\n           int indexToRemove &#061; rand() % keys.size();<br \/>\n           int keyToRemove &#061; keys[indexToRemove];<br \/>\n           cache.erase(keyToRemove);<br \/>\n           keys[indexToRemove] &#061; keys.back();<br \/>\n           keys.pop_back();<br \/>\n       }<br \/>\n       cache[key] &#061; value;<br \/>\n       keys.push_back(key);<br \/>\n   }<br \/>\n};<br \/>\nint main() {<br \/>\n   RRCache cache(2);<br \/>\n   cache.put(1, 1);<br \/>\n   cache.put(2, 2);<br \/>\n    std::cout &lt;&lt; cache.get(1) &lt;&lt; std::endl; \/\/returns 1<br \/>\n    cache.put(3, 3); \/\/evicts key 1 or 2 randomly<br \/>\n    std::cout &lt;&lt; cache.get(1) &lt;&lt; std::endl; \/\/returns -1 if key 1 is evicted, 1 otherwise<br \/>\n    std::cout &lt;&lt; cache.get(2) &lt;&lt; std::endl; \/\/returns -1 if key 2 is evicted, 2 otherwise<br \/>\n    cache.put(4, 4); \/\/evicts key 2 or 3 randomly<br \/>\n    std::cout &lt;&lt; cache.get(1) &lt;&lt; std::endl; \/\/always returns -1<br \/>\n    std::cout &lt;&lt; cache.get(2) &lt;&lt; std::endl; \/\/returns -1 if key 2 is evicted, 2 otherwise<br \/>\n    std::cout &lt;&lt; cache.get(3) &lt;&lt; std::endl; \/\/returns -1 if key 3 is evicted, 3 otherwise<br \/>\n    std::cout &lt;&lt; cache.get(4) &lt;&lt; std::endl; \/\/always returns 4<br \/>\n   return 0;<br \/>\n}<\/p>\n<p><span style=\"color:#000000\">\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d&#xff0c;\u6211\u4eec\u7ef4\u62a4\u4e86\u4e00\u4e2a vector \u7c7b\u578b\u7684 keys \u6765\u5b58\u50a8\u5f53\u524d\u7f13\u5b58\u4e2d\u7684\u6240\u6709\u952e&#xff0c;\u4ee5\u53ca\u4e00\u4e2a unordered map \u7c7b\u578b\u7684 cache \u6765\u5b58\u50a8\u952e\u503c\u5bf9\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">get \u51fd\u6570\u4f1a\u76f4\u63a5\u8fd4\u56de\u952e\u5bf9\u5e94\u7684\u503c&#xff08;\u5982\u679c\u8be5\u952e\u5b58\u5728\u4e8e\u7f13\u5b58\u4e2d&#xff09;\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">put \u51fd\u6570\u4f1a\u68c0\u67e5\u7f13\u5b58\u662f\u5426\u5df2\u8fbe\u5230\u5bb9\u91cf\u4e0a\u9650\u3002\u00a0\u5982\u679c\u5df2\u6ee1&#xff0c;\u5b83\u4f1a\u4ece keys \u5411\u91cf\u4e2d\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u952e&#xff0c;\u5c06\u5176\u4ece\u7f13\u5b58\u548c\u5411\u91cf\u4e2d\u79fb\u9664&#xff0c;\u7136\u540e\u5c06\u65b0\u7684\u952e\u503c\u5bf9\u6dfb\u52a0\u5230\u7f13\u5b58\u548c\u5411\u91cf\u4e2d\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8fd9\u79cd\u65b9\u6cd5\u7684\u7f3a\u70b9\u4e4b\u4e00\u662f\u6ca1\u6709\u8003\u8651\u7f13\u5b58\u4e2d\u9879\u76ee\u7684\u4f7f\u7528\u9891\u7387\u6216\u6700\u8fd1\u4f7f\u7528\u60c5\u51b5\u3002\u00a0\u4f46\u5176\u4f18\u52bf\u5728\u4e8e\u7b80\u5355\u9ad8\u6548&#xff0c;\u9002\u7528\u4e8e\u5176\u4ed6\u66ff\u6362\u65b9\u6cd5\u6548\u679c\u4e0d\u4f73\u6216\u7ef4\u62a4\u989d\u5916\u6570\u636e\u7ed3\u6784\u5f00\u9500\u8fc7\u5927\u7684\u5e94\u7528\u573a\u666f\u3002<\/span><\/p>\n<h2 id=\"aid_251\" style=\"text-align:justify\"><span style=\"color:#000000\">\u7f13\u5b58\u9519\u8bef\u6392\u67e5<\/span><\/h2>\n<p><span style=\"color:#000000\">\u867d\u7136\u7f13\u5b58\u80fd\u663e\u8457\u52a0\u5feb\u6570\u636e\u68c0\u7d22\u901f\u5ea6\u5e76\u51cf\u8f7b\u6570\u636e\u5e93\u6216\u5916\u90e8\u670d\u52a1\u7684\u8d1f\u8f7d&#xff0c;\u4f46\u5b83\u4e5f\u5e26\u6765\u4e86\u4e00\u7cfb\u5217\u5f00\u53d1\u8005\u9700\u8981\u5e94\u5bf9\u7684\u72ec\u7279\u6311\u6218&#xff0c;\u7279\u522b\u662f\u5728\u591a\u7528\u6237\u53ef\u80fd\u540c\u65f6\u4e0e\u6570\u636e\u4ea4\u4e92\u7684\u540e\u7aef\u5e94\u7528\u4e2d\u3002\u00a0\u8fd9\u4e9b\u6311\u6218\u5305\u62ec\u7f13\u5b58\u5931\u6548\u3001\u7f13\u5b58\u96ea\u5d29\u4ee5\u53ca\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\u7684\u6570\u636e\u4e00\u81f4\u6027\u7ef4\u62a4\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u5931\u6548<\/span><\/p>\n<p><span style=\"color:#000000\">\u5f53\u7f13\u5b58\u4e2d\u7684\u6570\u636e\u56e0\u6e90\u6570\u636e\u53d8\u66f4\u800c\u5931\u6548\u65f6&#xff0c;\u5c31\u4f1a\u51fa\u73b0\u7f13\u5b58\u5931\u6548\u8fd9\u4e00\u5e38\u89c1\u95ee\u9898\u3002\u00a0\u7f13\u5b58\u6570\u636e\u4e0e\u6e90\u6570\u636e\u4e4b\u95f4\u7684\u8fd9\u79cd\u5dee\u5f02\u53ef\u80fd\u5bfc\u81f4\u5411\u7528\u6237\u63d0\u4f9b\u8fc7\u65f6\u4fe1\u606f&#xff0c;\u4ece\u800c\u5f15\u53d1\u6570\u636e\u4e0d\u4e00\u81f4\u548c\u6f5c\u5728\u9519\u8bef\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u5904\u7406\u7f13\u5b58\u5931\u6548\u6709\u51e0\u79cd\u7b56\u7565&#xff1a;<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u751f\u5b58\u65f6\u95f4&#xff08;TTL&#xff09;\u7b56\u7565\u3002\u00a0\u5728\u8fd9\u79cd\u65b9\u6cd5\u4e2d&#xff0c;\u6bcf\u4e2a\u7f13\u5b58\u9879\u5728\u52a0\u5165\u7f13\u5b58\u65f6\u4f1a\u83b7\u5f97\u4e00\u4e2a\u65f6\u95f4\u6233\u3002\u00a0\u5982\u679c\u8bf7\u6c42\u8be5\u7f13\u5b58\u9879\u65f6\u53d1\u73b0\u65f6\u95f4\u6233\u8d85\u8fc7\u7279\u5b9a\u9608\u503c&#xff0c;\u5219\u7f13\u5b58\u5931\u6548&#xff0c;\u5e76\u4ece\u6570\u636e\u6e90\u83b7\u53d6\u6700\u65b0\u6570\u636e\u3002\u00a0\u8fd9\u79cd\u65b9\u6cd5\u786e\u4fdd\u6570\u636e\u4e0d\u4f1a\u65e0\u9650\u671f\u7559\u5728\u7f13\u5b58\u4e2d&#xff0c;\u5e76\u80fd\u5b9a\u671f\u5237\u65b0\u3002\u00a0\u4f46\u53ef\u80fd\u4e0d\u9002\u5408\u9891\u7e41\u6216\u4e0d\u53ef\u9884\u6d4b\u53d8\u5316\u7684\u6570\u636e\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u76f4\u5199&#xff08;Write-Through&#xff09;\u7b56\u7565\u3002\u00a0\u8fd9\u79cd\u65b9\u6cd5\u4f1a\u540c\u65f6\u66f4\u65b0\u7f13\u5b58\u548c\u6e90\u6570\u636e\u3002\u00a0\u8fd9\u80fd\u786e\u4fdd\u7f13\u5b58\u59cb\u7ec8\u53cd\u6620\u6570\u636e\u7684\u6700\u65b0\u72b6\u6001&#xff0c;\u4fdd\u6301\u4e00\u81f4\u6027\u3002\u00a0\u4f46\u7531\u4e8e\u6bcf\u6b21\u5199\u5165\u64cd\u4f5c\u90fd\u9700\u8981\u66f4\u65b0\u7f13\u5b58\u548c\u6e90\u6570\u636e&#xff0c;\u8fd9\u79cd\u65b9\u6cd5\u53ef\u80fd\u8f83\u6162\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u56de\u5199\u7b56\u7565\u662f\u53e6\u4e00\u79cd\u65b9\u6cd5&#xff0c;\u5176\u4e2d\u66f4\u6539\u9996\u5148\u5728\u7f13\u5b58\u4e2d\u8fdb\u884c&#xff0c;\u7136\u540e\u5f02\u6b65\u66f4\u65b0\u6e90\u6570\u636e\u3002\u00a0\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd&#xff0c;\u56e0\u4e3a\u5199\u64cd\u4f5c\u901f\u5ea6\u66f4\u5feb\u3002\u00a0\u4f46\u5982\u679c\u7cfb\u7edf\u5728\u6e90\u6570\u636e\u66f4\u65b0\u524d\u5d29\u6e83&#xff0c;\u4f1a\u589e\u52a0\u6570\u636e\u4e22\u5931\u7684\u98ce\u9669\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u96ea\u5d29<\/span><\/p>\n<p><span style=\"color:#000000\">\u7f13\u5b58\u96ea\u5d29\u662f\u53e6\u4e00\u4e2a\u6311\u6218&#xff0c;\u5f53\u591a\u4e2a\u7ebf\u7a0b\u8bd5\u56fe\u540c\u65f6\u751f\u6210\u76f8\u540c\u6570\u636e\u65f6\u53d1\u751f&#xff0c;\u901a\u5e38\u5728\u7f13\u5b58\u5931\u6548\u540e\u3002\u00a0\u8fd9\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u5e93\u8d1f\u8f7d\u8fc7\u91cd\u5e76\u964d\u4f4e\u6027\u80fd\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u6709\u51e0\u79cd\u7b56\u7565\u53ef\u4ee5\u9632\u6b62\u7f13\u5b58\u96ea\u5d29&#xff1a;<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u7f13\u5b58\u9501\u5b9a\u662f\u4e00\u79cd\u6280\u672f&#xff0c;\u5f53\u7ebf\u7a0b\u83b7\u53d6\u5230\u7a7a\u503c\u6216\u5df2\u5931\u6548\u7684\u7f13\u5b58\u9879\u65f6&#xff0c;\u4f1a\u7acb\u5373\u7528\u5360\u4f4d\u7b26\u503c\u66ff\u6362\u5b83\u3002\u00a0\u5728\u8be5\u7ebf\u7a0b\u83b7\u53d6\u65b0\u6570\u636e\u671f\u95f4&#xff0c;\u5176\u4ed6\u7ebf\u7a0b\u53ea\u4f1a\u770b\u5230\u5360\u4f4d\u7b26\u5e76\u77e5\u9053\u9700\u8981\u7b49\u5f85\u3002\u00a0\u8fd9\u6837\u53ef\u4ee5\u9632\u6b62\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u5c1d\u8bd5\u83b7\u53d6\u76f8\u540c\u6570\u636e\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u25cf\u00a0\u968f\u673a\u63d0\u524d\u8fc7\u671f\u662f\u53e6\u4e00\u79cd\u9632\u6b62\u7f13\u5b58\u96ea\u5d29\u7684\u7b56\u7565\u3002\u00a0\u4e0d\u540c\u4e8e\u4e00\u6b21\u6027\u4f7f\u6240\u6709\u7f13\u5b58\u9879\u5931\u6548&#xff0c;\u800c\u662f\u4e3a\u5b83\u4eec\u5206\u914d\u7565\u5fae\u968f\u673a\u7684 TTL \u503c\u3002\u00a0\u7531\u4e8e\u5e76\u975e\u6240\u6709\u9879\u90fd\u5728\u540c\u4e00\u65f6\u95f4\u5237\u65b0&#xff0c;\u8fd9\u80fd\u5206\u6563\u6570\u636e\u5e93\u7684\u8d1f\u8f7d\u538b\u529b\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u8282\u70b9\u4e0d\u4e00\u81f4\u6027<\/span><\/p>\n<p><span style=\"color:#000000\">\u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d&#xff0c;\u4fdd\u6301\u591a\u4e2a\u8282\u70b9\u95f4\u7684\u4e00\u81f4\u6027\u53ef\u80fd\u5177\u6709\u6311\u6218\u6027\u3002\u00a0\u5982\u679c\u6bcf\u4e2a\u8282\u70b9\u90fd\u7ef4\u62a4\u81ea\u5df1\u7684\u7f13\u5b58&#xff0c;\u90a3\u4e48\u5728\u4e00\u4e2a\u8282\u70b9\u4e0a\u5bf9\u6570\u636e\u6240\u505a\u7684\u66f4\u6539\u4e0d\u4f1a\u7acb\u5373\u53cd\u6620\u5728\u5176\u4ed6\u8282\u70b9\u7684\u7f13\u5b58\u4e2d\u3002\u00a0\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5206\u5e03\u5f0f\u7f13\u5b58\u540c\u6b65\u6765\u89e3\u51b3&#xff0c;\u4f46\u9700\u8981\u66f4\u591a\u8d44\u6e90\u4e14\u53ef\u80fd\u53d8\u5f97\u590d\u6742\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u901a\u8fc7\u7406\u89e3\u8fd9\u4e9b\u6311\u6218\u5e76\u5b9e\u65bd\u6709\u6548\u7684\u5e94\u5bf9\u7b56\u7565&#xff0c;\u5f00\u53d1\u8005\u53ef\u4ee5\u786e\u4fdd\u6784\u5efa\u53ef\u9760\u7684\u7f13\u5b58\u7cfb\u7edf&#xff0c;\u4ece\u800c\u51cf\u5c11\u6570\u636e\u5e93\u7684\u4e0d\u5fc5\u8981\u8d1f\u8f7d\u5e76\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u3002\u00a0\u5c3d\u7ba1\u5b58\u5728\u590d\u6742\u6027&#xff0c;\u7f13\u5b58\u5728\u63d0\u5347\u6027\u80fd\u548c\u6548\u7387\u65b9\u9762\u7684\u4f18\u52bf\u4f7f\u5176\u6210\u4e3a\u73b0\u4ee3\u8ba1\u7b97\u4e2d\u4e00\u9879\u6709\u4ef7\u503c\u7684\u6280\u672f\u3002<\/span><\/p>\n<h2 id=\"aid_92\" style=\"text-align:justify\"><span style=\"color:#000000\">\u603b\u7ed3<\/span><\/h2>\n<p><span style=\"color:#000000\">\u672c\u7ae0\u6df1\u5165\u63a2\u8ba8\u4e86\u7f13\u5b58\u6982\u5ff5\u53ca\u5176\u5728\u670d\u52a1\u5668\u7aef\u7f16\u7a0b\u4e2d\u7684\u6838\u5fc3\u4f5c\u7528\u3002\u00a0\u6211\u4eec\u4e86\u89e3\u5230\u7f13\u5b58\u662f\u4e00\u79cd\u5c06\u9891\u7e41\u8bbf\u95ee\u6570\u636e\u5b58\u50a8\u5728&#034;\u7f13\u5b58&#034;\u4e2d\u7684\u6280\u672f&#xff0c;\u53ef\u663e\u8457\u63d0\u5347\u5e94\u7528\u6027\u80fd\u5e76\u964d\u4f4e\u7f51\u7edc\u5ef6\u8fdf\u3002\u00a0\u91c7\u7528\u7684\u7f13\u5b58\u7c7b\u578b\u4e3b\u8981\u53d6\u51b3\u4e8e\u540e\u7aef\u7cfb\u7edf\u9700\u6c42\u53ca\u88ab\u7f13\u5b58\u6570\u636e\u7684\u7279\u6027\u3002\u00a0\u4ee5\u6570\u636e\u5e93\u7f13\u5b58\u4e3a\u4f8b&#xff0c;\u5176\u91cd\u70b9\u5728\u4e8e\u5b58\u50a8\u6570\u636e\u5e93\u67e5\u8be2\u7ed3\u679c&#xff0c;\u8fd9\u5bf9\u51cf\u8f7b\u6570\u636e\u5e93\u8d1f\u8f7d\u548c\u63d0\u5347\u5e94\u7528\u54cd\u5e94\u901f\u5ea6\u81f3\u5173\u91cd\u8981\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u968f\u540e\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5728\u57fa\u4e8e MongoDB \u7684\u535a\u5ba2\u5e94\u7528\u4e2d\u5b9e\u73b0\u7f13\u5b58\u7684\u5b8c\u6574\u6d41\u7a0b\u3002\u00a0\u8fd9\u4e2a\u5b9e\u8df5\u7ec3\u4e60\u751f\u52a8\u5c55\u793a\u4e86\u7f13\u5b58\u63d2\u5165\u3001\u7f13\u5b58\u68c0\u7d22\u548c\u7f13\u5b58\u6dd8\u6c70\u7684\u6838\u5fc3\u6982\u5ff5&#xff0c;\u5e76\u6f14\u793a\u4e86\u4ece\u7b80\u5355\u7684\u751f\u5b58\u65f6\u95f4(TTL)\u65b9\u6cd5\u5230\u66f4\u590d\u6742\u7684\u900f\u5199\u4e0e\u56de\u5199\u7b49\u591a\u79cd\u5b9e\u73b0\u7b56\u7565\u3002\u00a0\u6b64\u5916&#xff0c;\u6211\u4eec\u8fd8\u63a2\u8ba8\u4e86\u5982\u4f55\u5229\u7528 Google \u7684 gRPC \u6846\u67b6\u901a\u8fc7 HTTP\/2 \u534f\u8bae\u548c\u4e8c\u8fdb\u5236\u6570\u636e\u683c\u5f0f\u7b49\u9ad8\u7ea7\u7279\u6027\u6765\u589e\u5f3a\u670d\u52a1\u7aef\u7f13\u5b58&#xff0c;\u4ece\u800c\u663e\u8457\u63d0\u5347\u6570\u636e\u4f20\u8f93\u6548\u7387\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u6700\u540e&#xff0c;\u6211\u4eec\u63a2\u8ba8\u4e86\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565&#xff0c;\u5982\u6700\u8fd1\u6700\u5c11\u4f7f\u7528(LRU)\u3001\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528(LFU)\u548c\u968f\u673a\u66ff\u6362(RR)&#xff0c;\u5e76\u8ba8\u8bba\u4e86\u5b83\u4eec\u5404\u81ea\u7684\u9002\u7528\u573a\u666f\u548c\u5b9e\u73b0\u7ec6\u8282\u3002\u00a0\u5728\u6b64\u8fc7\u7a0b\u4e2d&#xff0c;\u6211\u4eec\u8fd8\u53d1\u73b0\u4e86\u4f7f\u7528\u7f13\u5b58\u65f6\u53ef\u80fd\u9047\u5230\u7684\u6f5c\u5728\u9677\u9631\u548c\u5e38\u89c1\u95ee\u9898&#xff0c;\u5305\u62ec\u7f13\u5b58\u5931\u6548\u3001\u7f13\u5b58\u96ea\u5d29\u548c\u4e00\u81f4\u6027\u95ee\u9898\u3002\u00a0\u6700\u540e\u6211\u4eec\u5b66\u4e60\u4e86\u6709\u6548\u5904\u7406\u8fd9\u4e9b\u95ee\u9898\u7684\u7b56\u7565&#xff0c;\u4f8b\u5982\u4f7f\u7528\u7f13\u5b58\u9501\u5b9a\u7b56\u7565\u6216\u7f13\u5b58\u9884\u70ed\u7b56\u7565\u6765\u9632\u6b62\u7f13\u5b58\u96ea\u5d29\u3002\u00a0\u672c\u7ae0\u5168\u9762\u4ecb\u7ecd\u4e86\u670d\u52a1\u7aef\u7f16\u7a0b\u4e2d\u7684\u7f13\u5b58\u673a\u5236&#xff0c;\u5e76\u8be6\u7ec6\u9610\u8ff0\u4e86\u5982\u4f55\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u6709\u6548\u5b9e\u65bd\u548c\u7ba1\u7406\u7f13\u5b58\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb969\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf21\u6b21\u3002\u5728\u6b64\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u8fd8\u53d1\u73b0\u4e86\u4f7f\u7528\u7f13\u5b58\u65f6\u53ef\u80fd\u9047\u5230\u7684\u6f5c\u5728\u9677\u9631\u548c\u5e38\u89c1\u95ee\u9898\uff0c\u5305\u62ec\u7f13\u5b58\u5931\u6548\u3001\u7f13\u5b58\u96ea\u5d29\u548c\u4e00\u81f4\u6027\u95ee\u9898\u3002\u5b58\u5728\u591a\u79cd\u4e0d\u540c\u7684\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\uff0c\u4f46\u5728\u672c\u6b21\u8ba8\u8bba\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u4e09\u79cd\u6700\u5e38\u7528\u7684\u7b56\u7565\uff1a\u6700\u8fd1\u6700\u5c11\u4f7f\u7528(LRU)\u3001\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528(LFU)\u548c\u968f\u673a\u66ff\u6362(RR)\u3002\u8fd9\u4e2a\u5b9e\u8df5\u7ec3\u4e60\u751f\u52a8\u5c55\u793a\u4e86\u7f13\u5b58\u63d2\u5165\u3001\u7f13\u5b58\u68c0\u7d22\u548c\u7f13\u5b58\u6dd8\u6c70\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5e76\u6f14\u793a\u4e86\u4ece\u7b80\u5355\u7684\u751f\u5b58\u65f6\u95f4(TTL)\u65b9\u6cd5\u5230\u66f4\u590d\u6742\u7684\u900f\u5199\u4e0e\u56de\u5199\u7b49\u591a\u79cd\u5b9e\u73b0\u7b56\u7565\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u4e2a\u535a\u5ba2\u5e94\u7528\u4e2d\u7f13\u5b58\u6700\u8fd1\u8bbf\u95ee\u7684\u535a\u5ba2\u6587\u7ae0\u65f6\uff0c\u5f53\u7f13\u5b58\u7a7a\u95f4\u4e0d\u8db3\u65f6\uff0cLRU \u7b56\u7565\u4f1a\u8981\u6c42\u6211\u4eec\u4e22\u5f03\u6700\u957f\u65f6\u95f4\u672a\u88ab\u8bbf\u95ee\u7684\u6587\u7ae0\u3002<\/p>\n","protected":false},"author":2,"featured_media":58481,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4489,87,100,43],"topic":[],"class_list":["post-58483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-87","tag-100","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 7 \u5904\u7406\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u7f13\u5b58 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/58483.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 7 \u5904\u7406\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u7f13\u5b58 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb969\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf21\u6b21\u3002\u5728\u6b64\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u8fd8\u53d1\u73b0\u4e86\u4f7f\u7528\u7f13\u5b58\u65f6\u53ef\u80fd\u9047\u5230\u7684\u6f5c\u5728\u9677\u9631\u548c\u5e38\u89c1\u95ee\u9898\uff0c\u5305\u62ec\u7f13\u5b58\u5931\u6548\u3001\u7f13\u5b58\u96ea\u5d29\u548c\u4e00\u81f4\u6027\u95ee\u9898\u3002\u5b58\u5728\u591a\u79cd\u4e0d\u540c\u7684\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\uff0c\u4f46\u5728\u672c\u6b21\u8ba8\u8bba\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u4e09\u79cd\u6700\u5e38\u7528\u7684\u7b56\u7565\uff1a\u6700\u8fd1\u6700\u5c11\u4f7f\u7528(LRU)\u3001\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528(LFU)\u548c\u968f\u673a\u66ff\u6362(RR)\u3002\u8fd9\u4e2a\u5b9e\u8df5\u7ec3\u4e60\u751f\u52a8\u5c55\u793a\u4e86\u7f13\u5b58\u63d2\u5165\u3001\u7f13\u5b58\u68c0\u7d22\u548c\u7f13\u5b58\u6dd8\u6c70\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5e76\u6f14\u793a\u4e86\u4ece\u7b80\u5355\u7684\u751f\u5b58\u65f6\u95f4(TTL)\u65b9\u6cd5\u5230\u66f4\u590d\u6742\u7684\u900f\u5199\u4e0e\u56de\u5199\u7b49\u591a\u79cd\u5b9e\u73b0\u7b56\u7565\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u4e2a\u535a\u5ba2\u5e94\u7528\u4e2d\u7f13\u5b58\u6700\u8fd1\u8bbf\u95ee\u7684\u535a\u5ba2\u6587\u7ae0\u65f6\uff0c\u5f53\u7f13\u5b58\u7a7a\u95f4\u4e0d\u8db3\u65f6\uff0cLRU \u7b56\u7565\u4f1a\u8981\u6c42\u6211\u4eec\u4e22\u5f03\u6700\u957f\u65f6\u95f4\u672a\u88ab\u8bbf\u95ee\u7684\u6587\u7ae0\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/58483.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-16T03:25:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250816032518-689ffa1edadcf.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/58483.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/58483.html\",\"name\":\"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 7 \u5904\u7406\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u7f13\u5b58 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-16T03:25:21+00:00\",\"dateModified\":\"2025-08-16T03:25:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/58483.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/58483.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/58483.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 7 \u5904\u7406\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u7f13\u5b58\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 7 \u5904\u7406\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u7f13\u5b58 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/58483.html","og_locale":"zh_CN","og_type":"article","og_title":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 7 \u5904\u7406\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u7f13\u5b58 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb969\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf21\u6b21\u3002\u5728\u6b64\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u8fd8\u53d1\u73b0\u4e86\u4f7f\u7528\u7f13\u5b58\u65f6\u53ef\u80fd\u9047\u5230\u7684\u6f5c\u5728\u9677\u9631\u548c\u5e38\u89c1\u95ee\u9898\uff0c\u5305\u62ec\u7f13\u5b58\u5931\u6548\u3001\u7f13\u5b58\u96ea\u5d29\u548c\u4e00\u81f4\u6027\u95ee\u9898\u3002\u5b58\u5728\u591a\u79cd\u4e0d\u540c\u7684\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\uff0c\u4f46\u5728\u672c\u6b21\u8ba8\u8bba\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u4e09\u79cd\u6700\u5e38\u7528\u7684\u7b56\u7565\uff1a\u6700\u8fd1\u6700\u5c11\u4f7f\u7528(LRU)\u3001\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528(LFU)\u548c\u968f\u673a\u66ff\u6362(RR)\u3002\u8fd9\u4e2a\u5b9e\u8df5\u7ec3\u4e60\u751f\u52a8\u5c55\u793a\u4e86\u7f13\u5b58\u63d2\u5165\u3001\u7f13\u5b58\u68c0\u7d22\u548c\u7f13\u5b58\u6dd8\u6c70\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5e76\u6f14\u793a\u4e86\u4ece\u7b80\u5355\u7684\u751f\u5b58\u65f6\u95f4(TTL)\u65b9\u6cd5\u5230\u66f4\u590d\u6742\u7684\u900f\u5199\u4e0e\u56de\u5199\u7b49\u591a\u79cd\u5b9e\u73b0\u7b56\u7565\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u4e2a\u535a\u5ba2\u5e94\u7528\u4e2d\u7f13\u5b58\u6700\u8fd1\u8bbf\u95ee\u7684\u535a\u5ba2\u6587\u7ae0\u65f6\uff0c\u5f53\u7f13\u5b58\u7a7a\u95f4\u4e0d\u8db3\u65f6\uff0cLRU \u7b56\u7565\u4f1a\u8981\u6c42\u6211\u4eec\u4e22\u5f03\u6700\u957f\u65f6\u95f4\u672a\u88ab\u8bbf\u95ee\u7684\u6587\u7ae0\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/58483.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-16T03:25:21+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250816032518-689ffa1edadcf.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/58483.html","url":"https:\/\/www.wsisp.com\/helps\/58483.html","name":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 7 \u5904\u7406\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u7f13\u5b58 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-16T03:25:21+00:00","dateModified":"2025-08-16T03:25:21+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/58483.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/58483.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/58483.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++\u540e\u7aef\u7f16\u7a0b \u6784\u5efa\u9ad8\u6027\u80fd\u540e\u7aef\u7684\u6570\u636e\u5e93\u3001API \u4e0e Web \u670d\u52a1\u5668 7 \u5904\u7406\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u7f13\u5b58"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/58483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=58483"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/58483\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/58481"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=58483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=58483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=58483"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=58483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}