{"id":29176,"date":"2024-11-25T08:08:42","date_gmt":"2024-11-25T00:08:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29176\/"},"modified":"2024-11-25T08:08:42","modified_gmt":"2024-11-25T00:08:42","slug":"wordpress-%e5%af%b9%e8%b1%a1%e7%bc%93%e5%ad%98%ef%bc%88object-cache%ef%bc%89%e8%af%a6%e7%bb%86%e4%bb%8b%e7%bb%8d%e5%92%8c%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29176\/","title":{"rendered":"WordPress \u5bf9\u8c61\u7f13\u5b58\uff08Object Cache\uff09\u8be6\u7ec6\u4ecb\u7ecd\u548c\u4f7f\u7528"},"content":{"rendered":"<p>memcached \u5185\u5b58\u7f13\u5b58\u53ef\u4ee5\u4f18\u5316  \u5f88\u591a\u529f\u80fd\uff0c\u8ba9\u4f60\u7684 wordpress \u53d8\u5f97\u66f4\u5feb\uff0c\u4e0b\u9762\u7531\u680f\u76ee\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 memcached \u6765\u6df1\u5ea6\u4f18\u5316 wordpress\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/020\/5d91784532d48899.jpg\" class=\"aligncenter\" title=\"WordPress \u5bf9\u8c61\u7f13\u5b58\uff08Object Cache\uff09\u8be6\u7ec6\u4ecb\u7ecd\u548c\u4f7f\u7528\u63d2\u56fe\" alt=\"WordPress \u5bf9\u8c61\u7f13\u5b58\uff08Object Cache\uff09\u8be6\u7ec6\u4ecb\u7ecd\u548c\u4f7f\u7528\u63d2\u56fe\" \/><\/p>\n<p>\u8981\u6df1\u5ea6\u7406\u89e3 WordPress \u4f18\u5316\uff0c\u5fc5\u987b\u8981\u9996\u5148\u4e86\u89e3 WordPress \u5bf9\u8c61\u7f13\u5b58 \u673a\u5236\u3002<\/p>\n<p><strong>WordPress \u5bf9\u8c61\u7f13\u5b58\u673a\u5236\u548c\u670d\u52a1\u5668\u8bbe\u7f6e<\/strong><\/p>\n<p>WordPress Object Cache\uff08WordPress \u5bf9\u8c61\u7f13\u5b58\uff09\u662f WordPress \u7684\u7f13\u5b58\u673a\u5236\uff0c\u5b83\u7684\u4e3b\u8981\u529f\u80fd\u662f\u628a\u8d1f\u8d23\u67e5\u8be2\u6216\u8005\u8fd0\u7b97\u7684\u7ed3\u679c\u6309\u7167 Key-Value \u8fd9\u6837\u7684\u65b9\u5f0f\uff08WordPress \u8fd8\u652f\u6301\u6309\u7167 Group \u6765\u5212\u5206\u548c\u907f\u514d\u7f13\u5b58\u7684\u5185\u5bb9\u51b2\u7a81\uff09\u5b58\u50a8\u5230\u5bf9\u8c61\u91cc\u9762\uff0c\u4e0b\u6b21\u8fdb\u884c\u540c\u6837\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u8ba9\u76f4\u63a5\u4ece\u8fd9\u4e2a\u5bf9\u8c61\u4e2d\u53d6\u51fa\u6570\u636e\uff0c\u4e0d\u7528\u91cd\u590d\u5230\u6570\u636e\u5e93\u4e2d\u6216\u8005\u5176\u4ed6\u5916\u90e8\u7f51\u7ad9\u83b7\u53d6\u6570\u636e\u3002<\/p>\n<p>WordPress Object Cache \u548c\u670d\u52a1\u5668\u8bbe\u7f6e\u5173\u7cfb\u5f88\u5927\uff0c\u5982\u679c\u7cfb\u7edf\u5f00\u542f\u4e86 Memcached \u5185\u5b58\u7f13\u5b58\uff0c\u5219\u8fd9\u4e2a\u5bf9\u8c61\u662f\u76f4\u63a5\u5b58\u5165\u5230\u5185\u5b58\uff0c\u5728\u6570\u636e\u672a\u8fc7\u671f\u4e4b\u524d\uff0c\u4ee5\u540e\u518d\u6b21\u8bfb\u53d6\u8fd9\u4e2a\u6570\u636e\u90fd\u662f\u76f4\u63a5\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u7684\uff0c\u8fd9\u6837\u6548\u7387\u548c\u901f\u5ea6\u90fd\u975e\u5e38\u5feb\u7684\u3002<\/p>\n<p>\u5982\u679c\u670d\u52a1\u5668\u4e0d\u652f\u6301\u5185\u5b58\u7f13\u5b58\u7684\u8bdd\uff0c\u5219\u53ea\u80fd\u4fdd\u8bc1\u5728\u5f53\u524d\u9875\u9762\u4e0b\u540c\u6837\u7684\u67e5\u8be2\u6216\u8005\u64cd\u4f5c\u4e0d\u518d\u91cd\u590d\u4ece\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u4e86\u3002<\/p>\n<p><strong>WordPress \u5bf9\u8c61\u7f13\u5b58\u7684\u51fd\u6570<\/strong><\/p>\n<p>\u4f7f\u7528 WordPress \u5bf9\u8c61\u7f13\u5b58\u6280\u672f\u5176\u5b9e\u662f\u975e\u5e38\u7b80\u5355\u7684\uff1a<\/p>\n<p>\u4f7f\u7528 wp_cache_add() \u628a\u6570\u636e\u6dfb\u52a0\u5230\u7f13\u5b58\u4e2d\u3002<\/p>\n<p>\u4f7f\u7528 wp_cache_set() \u628a\u6570\u636e\u8bbe\u7f6e\u5230\u7f13\u5b58\u4e2d\u3002<\/p>\n<p>\u4f7f\u7528 wp_cache_get() \u5230\u7f13\u5b58\u4e2d\u8bfb\u53d6\u6570\u636e\u3002<\/p>\n<p>\u4f7f\u7528 wp_cache_delete() \u5220\u9664\u7f13\u5b58\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<p>\u8fd9\u4e9b\u51fd\u6570\u4f1a\u6d89\u53ca\u5230\u7684\u56db\u4e2a\u53c2\u6570\uff1a<\/p>\n<p><strong>\u53c2\u6570&nbsp;<\/strong><\/p>\n<p>$key \u5bf9\u8c61\u7684 key\u3002<\/p>\n<p>$data \u8981\u5b58\u7684\u503c\u3002<\/p>\n<p>$group \u5206\u7ec4\uff0c\u53ef\u9009\u53c2\u6570\uff0c\u7528\u6765\u628a\u7f13\u5b58\u5bf9\u8c61\u5c31\u884c\u5206\u7ec4\u3002<\/p>\n<p>$expire \u8fc7\u671f\u65f6\u95f4\uff0c\u53ef\u9009\u53c2\u6570\uff0c\u5982\u679c\u662f\u9ed8\u8ba4\u7f13\u5b58\uff0c\u8fd9\u4e2a\u53c2\u6570\u6ca1\u7528\uff0c\u5982\u679c\u662f\u5185\u5b58\u7f13\u5b58\uff0c\u662f\u8bbe\u7f6e\u7f13\u5b58\u7684\u65f6\u95f4\uff0c\u5355\u4f4d\u662f\u79d2\uff0c\u9ed8\u8ba4\u4e3a0\uff080\u7684\u610f\u601d\u5c31\u662f\u6c38\u8fdc\uff0c\u4e0d\u4f1a\u81ea\u52a8\u8fc7\u671f\uff09\u3002<\/p>\n<p><strong>\u4f7f\u7528 WordPress \u5bf9\u8c61\u7f13\u5b58<\/strong><\/p>\n<p>\u4e0b\u9762\u4ee5\u6211\u5373\u5c06\u66f4\u65b0 WordPress \u76f8\u5173\u6587\u7ae0\u63d2\u4ef6\u4e3a\u4f8b\uff0c\u8bb2\u8bb2\u5982\u4f55\u4f7f\u7528 WordPress \u5bf9\u8c61\u7f13\u5b58\uff1a<\/p>\n<p>\u6211\u4eec\u77e5\u9053 WordPress \u76f8\u5173\u6587\u7ae0\u63d2\u4ef6\u662f\u901a\u8fc7 tag \u548c\u5206\u7c7b\u6765\u83b7\u53d6\u76f8\u5173\u6587\u7ae0\uff0c\u76f8\u540c\u7684 tag \u548c\u5206\u7c7b\u8d8a\u591a\uff0c\u76f8\u5173\u6027\u8d8a\u5f3a\uff0c\u8fd9\u6837\u5c31\u9700\u8981\u8fdb\u884c\u591a\u4e2a\u8868\u8054\u5408\u67e5\u8be2\u6765\u83b7\u53d6\u76f8\u5173\u6587\u7ae0\uff0c\u8fd9\u6837\u6548\u7387\u5176\u5b9e\u662f\u6bd4\u8f83\u5dee\u7684\u3002\u4f46\u662f\u4e00\u4e2a\u6587\u7ae0\u5b83\u7684\u76f8\u5173\u6587\u7ae0\u4e00\u6bb5\u65f6\u95f4\u5185\u662f\u4e0d\u4f1a\u53d8\u52a8\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528 WordPress \u5bf9\u8c61\u7f13\u5b58\u5bf9\u76f8\u5173\u6587\u7ae0\u8fdb\u884c\u52a0\u901f\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u628a\u628a\u76f8\u5173\u6587\u7ae0\u7684\u6570\u636e\u5199\u5165\u7f13\u5b58\u7684\u4f8b\u5b50\uff0c\u4f7f\u7528\u5f53\u524d post_id \u4f5c\u4e3a key\uff0crelated_posts \u4f5c\u4e3a group\uff0c\u7f13\u5b58\u65f6\u95f4\u4e3a\u4e00\u4e2a\u5c0f\u65f6\uff0c\u5373 3600 \u79d2\u3002<\/p>\n<pre>global&nbsp;$post;\n$related_posts_data&nbsp;=&nbsp;wp_get_related_posts();\nwp_cache_set($post-&amp;gt;ID,$related_posts_data,'related_posts',3600);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e0a\u9762\u53ea\u662f\u628a\u6570\u636e\u5b58\u5230\u7f13\u5b58\u5bf9\u8c61\u4e2d\uff0c\u6211\u4eec\u5728\u663e\u793a\u76f8\u5173\u6587\u7ae0\u7684\u65f6\u5019\uff0c\u5c31\u8981\u53bb\u8c03\u7528\u8fd9\u4e2a\u5bf9\u8c61\u7f13\u5b58\u6765\u4f7f\u7528\uff0c\u9996\u5148\u68c0\u67e5\u4e0b\u662f\u5426\u5df2\u7ecf\u6709\u4e86\u7f13\u5b58\uff0c\u5982\u679c\u4f60\u8981\u7684\u4fe1\u606f\u6ca1\u6709\u5728\u7f13\u5b58\u4e2d\uff0c\u6216\u8005\u5df2\u7ecf\u8fc7\u671f\u4e86\u3002wp_cache_get() \u4f1a\u8fd4\u56de false\uff0c\u5982\u679c\u8fd9\u6837\uff0c\u4f60\u5c31\u8981\u53bb\u6570\u636e\u5e93\u4e2d\u91cd\u65b0\u83b7\u53d6\u8fd9\u4e9b\u4fe1\u606f\u3002\u5426\u5219\u5c31\u8fd4\u56de\u5728\u7f13\u5b58\u4e2d\u7684\u4fe1\u606f\u3002<\/p>\n<pre>global&nbsp;$post;\n$related_posts_data&nbsp;=&nbsp;wp_cache_get($post-&amp;gt;ID,'related_posts');\nif(false&nbsp;===&nbsp;$related_posts_data){\n$related_posts_data&nbsp;=&nbsp;wp_get_related_posts();\nwp_cache_set($post-&amp;gt;ID,$related_posts_data,'related_posts',3600);\n}\necho&nbsp;$related_posts_data;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u56e0\u4e3a\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u5c0f\u65f6\uff0c\u76f8\u5173\u6587\u7ae0\u7684\u6570\u636e\u5c31\u5931\u6548\uff0c\u8fd9\u91cc\u4e00\u822c\u5c31\u65e0\u9700\u66f4\u65b0\u7f13\u5b58\u4e86\uff0c\u5982\u679c\u4f60\u5728\u540e\u53f0\u66f4\u6539\u4e86\u8bbe\u7f6e\uff0c\u9700\u8981\u7acb\u5373\u6e05\u7406\u7f13\u5b58\uff0c\u53ef\u4ee5\u4f7f\u7528 wp_cache_delete \u8fdb\u884c\u6e05\u7406:<\/p>\n<pre>wp_cacache_delete($post-&amp;gt;ID,'related_posts');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>WPJAM Basic \u63d2\u4ef6\u5df2\u7ecf\u96c6\u6210\u4e86 Memcached\uff0c\u4e0b\u8f7d WPJAM Basic \u4e4b\u540e\uff0c\u5c06 wpjam-basic\/template\/ \u76ee\u5f55\u4e0b\u7684 object-cache.php \u6587\u4ef6\u590d\u5236\u5230 wp-content \u76ee\u5f55\u4e0b\u5373\u53ef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fWordPress \u5bf9\u8c61\u7f13\u5b58\uff08Object Cache\uff09\u8be6\u7ec6\u4ecb\u7ecd\u548c\u4f7f\u7528\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>memcached \u5185\u5b58\u7f13\u5b58\u53ef\u4ee5\u4f18\u5316 \u5f88\u591a\u529f\u80fd\uff0c\u8ba9\u4f60\u7684 wordpress \u53d8\u5f97\u66f4\u5feb\uff0c\u4e0b\u9762\u7531\u680f\u76ee\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 memcached \u6765\u6df1\u5ea6\u4f18\u5316 wordpress\u3002 \u8981\u6df1\u5ea6\u7406\u89e3 WordPress \u4f18\u5316\uff0c\u5fc5\u987b\u8981\u9996\u5148\u4e86\u89e3 WordPress \u5bf9\u8c61\u7f13\u5b58 \u673a\u5236\u3002 WordPress \u5bf9\u8c61\u7f13\u5b58\u673a\u5236\u548c\u670d\u52a1\u5668\u8bbe\u7f6e WordPress Object Cache\uff08WordPress \u5bf9\u8c61\u7f13\u5b58\uff09\u662f WordPress \u7684\u7f13\u5b58\u673a\u5236\uff0c\u5b83\u7684\u4e3b\u8981\u529f\u80fd\u662f\u628a\u8d1f\u8d23\u67e5\u8be2\u6216\u8005\u8fd0\u7b97\u7684\u7ed3\u679c\u6309\u7167 Key-Value \u8fd9\u6837\u7684\u65b9\u5f0f\uff08WordPress \u8fd8\u652f\u6301\u6309\u7167 Group \u6765\u5212\u5206\u548c\u907f\u514d\u7f13\u5b58\u7684\u5185\u5bb9\u51b2\u7a81\uff09\u5b58\u50a8\u5230\u5bf9\u8c61\u91cc\u9762\uff0c\u4e0b\u6b21\u8fdb\u884c\u540c\u6837\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u8ba9\u76f4\u63a5\u4ece\u8fd9\u4e2a\u5bf9\u8c61\u4e2d\u53d6\u51fa\u6570\u636e\uff0c\u4e0d\u7528\u91cd\u590d\u5230\u6570\u636e\u5e93\u4e2d\u6216\u8005\u5176\u4ed6\u5916\u90e8\u7f51\u7ad9\u83b7\u53d6\u6570\u636e\u3002 WordPress Object Cache \u548c\u670d\u52a1\u5668\u8bbe\u7f6e\u5173\u7cfb\u5f88\u5927\uff0c\u5982\u679c\u7cfb\u7edf\u5f00\u542f\u4e86 Memcached \u5185\u5b58\u7f13\u5b58\uff0c\u5219\u8fd9\u4e2a\u5bf9\u8c61\u662f\u76f4\u63a5\u5b58\u5165\u5230\u5185\u5b58\uff0c\u5728\u6570\u636e\u672a\u8fc7\u671f\u4e4b\u524d\uff0c\u4ee5\u540e\u518d\u6b21\u8bfb\u53d6\u8fd9\u4e2a\u6570\u636e\u90fd\u662f\u76f4\u63a5\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u7684\uff0c\u8fd9\u6837\u6548\u7387\u548c\u901f\u5ea6\u90fd\u975e\u5e38\u5feb\u7684\u3002 \u5982\u679c\u670d\u52a1\u5668\u4e0d\u652f\u6301\u5185\u5b58\u7f13\u5b58\u7684\u8bdd\uff0c\u5219\u53ea\u80fd\u4fdd\u8bc1\u5728\u5f53\u524d\u9875\u9762\u4e0b\u540c\u6837\u7684\u67e5\u8be2\u6216\u8005\u64cd\u4f5c\u4e0d\u518d\u91cd\u590d\u4ece\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u4e86\u3002 WordPress \u5bf9\u8c61\u7f13\u5b58\u7684\u51fd\u6570 \u4f7f\u7528 WordPress \u5bf9\u8c61\u7f13\u5b58\u6280\u672f\u5176\u5b9e\u662f\u975e\u5e38\u7b80\u5355\u7684\uff1a \u4f7f\u7528 wp_cache_add() \u628a\u6570\u636e\u6dfb\u52a0\u5230\u7f13\u5b58\u4e2d\u3002 \u4f7f\u7528 wp_cache_set() \u628a\u6570\u636e\u8bbe\u7f6e\u5230\u7f13\u5b58\u4e2d\u3002 \u4f7f\u7528 wp_cache_get() \u5230\u7f13\u5b58\u4e2d\u8bfb\u53d6\u6570\u636e\u3002 \u4f7f\u7528 wp_cache_delete() \u5220\u9664\u7f13\u5b58\u4e2d\u7684\u6570\u636e\u3002 \u8fd9\u4e9b\u51fd\u6570\u4f1a\u6d89\u53ca\u5230\u7684\u56db\u4e2a\u53c2\u6570\uff1a \u53c2\u6570&nbsp; $key \u5bf9\u8c61\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-29176","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=29176"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29176\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}