{"id":34398,"date":"2023-02-11T20:05:22","date_gmt":"2023-04-18T23:21:01","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/"},"modified":"2024-01-15T08:16:25","modified_gmt":"2024-01-15T00:16:25","slug":"%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/","title":{"rendered":"\u4f7f\u7528Ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u5728\u6574\u7406\u6211\u4ee5\u524d\u5199\u7684Class\u65f6\uff0c\u53d1\u73b0\u6709\u4e00\u4e9b\u4e0d\u592a\u597d\u7684\u5730\u65b9\uff0c\u56e0\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u4e0d\u540c\uff0c\u6240\u4ee5\u6211\u51c6\u5907\u4e86\u53e6\u4e00\u4e2aClass\u6765\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6700\u8fd1\u6211\u5f00\u59cb\u4f7f\u7528\u53ef\u53d8\u53c2\u6570\u6765\u8fdb\u884c\u6574\u5408\u3002<\/p>\n<h2>1. \u5185\u5bb9<\/h2>\n<p>\u4f8b\uff1a<br \/>\n\u53ea\u9700\u8981\u8fdb\u884c\u503c\u7684\u8bbe\u7f6e\/\u83b7\u53d6\u64cd\u4f5c\u7684\u7c7b\uff0c\u5728Memcache\u64cd\u4f5c\u4e2d\u662f\u5fc5\u8981\u7684\u3002<\/p>\n<pre class=\"post-pre\"><code>class MemCacheR\r\n\r\n    include Singleton\r\n    attr_accessor :x, :y, :z\r\n\r\n    def initialize(*args)\r\n        @x, @y, @z = args\r\n    end\r\n\r\n    def mem_get(*args)\r\n       x = args[0]\r\n       y = args[1]\r\n       cache = MemCache.new('127.0.0.1:11211')\r\n       cache.get(x+y)\r\n    end\r\n\r\n    def mem_set(*args)\r\n      x = args[0]\r\n      y = args[1]\r\n      z = args[2]\r\n      z ||= 0\r\n      cache = MemCache.new('127.0.0.1:11211')\r\n      cache[x+y]= z\r\n    end\r\nend\r\n<\/code><\/pre>\n<p>\u5229\u7528X\u548cY\u751f\u6210\u5bc6\u94a5\uff0cZ\u4e3a\u503c\u3002<\/p>\n<h2>\u786e\u8ba4<\/h2>\n<pre class=\"post-pre\"><code>MemCacheR.instance.mem_set(\"hogehoge\", \"1111111\", 500000)\r\na =  MemCacheR.instance.mem_get(\"hogehoge\", \"1111111\")\r\np a\r\n500000\r\n<\/code><\/pre>\n<p>\u53ea\u8981\u80fd\u591f\u53d6\u5f97\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6574\u7406\u6211\u4ee5\u524d\u5199\u7684Class\u65f6\uff0c\u53d1\u73b0\u6709\u4e00\u4e9b\u4e0d\u592a\u597d\u7684\u5730\u65b9\uff0c\u56e0\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u4e0d\u540c\uff0c\u6240\u4ee5\u6211\u51c6\u5907\u4e86\u53e6\u4e00\u4e2aClass\u6765\u8fdb [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-34398","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528Ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5 - Blog - Silicon Cloud<\/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.silicloud.com\/zh\/blog\/\u4f7f\u7528ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528Ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5\" \/>\n<meta property=\"og:description\" content=\"\u5728\u6574\u7406\u6211\u4ee5\u524d\u5199\u7684Class\u65f6\uff0c\u53d1\u73b0\u6709\u4e00\u4e9b\u4e0d\u592a\u597d\u7684\u5730\u65b9\uff0c\u56e0\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u4e0d\u540c\uff0c\u6240\u4ee5\u6211\u51c6\u5907\u4e86\u53e6\u4e00\u4e2aClass\u6765\u8fdb [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-18T23:21:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-15T00:16:25+00:00\" \/>\n<meta name=\"author\" content=\"\u6e05, \u5b87\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u5b87\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/\",\"name\":\"\u4f7f\u7528Ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-04-18T23:21:01+00:00\",\"dateModified\":\"2024-01-15T00:16:25+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528Ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\",\"name\":\"\u6e05, \u5b87\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u5b87\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528Ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5 - Blog - Silicon Cloud","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.silicloud.com\/zh\/blog\/\u4f7f\u7528ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528Ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5","og_description":"\u5728\u6574\u7406\u6211\u4ee5\u524d\u5199\u7684Class\u65f6\uff0c\u53d1\u73b0\u6709\u4e00\u4e9b\u4e0d\u592a\u597d\u7684\u5730\u65b9\uff0c\u56e0\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u4e0d\u540c\uff0c\u6240\u4ee5\u6211\u51c6\u5907\u4e86\u53e6\u4e00\u4e2aClass\u6765\u8fdb [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-04-18T23:21:01+00:00","article_modified_time":"2024-01-15T00:16:25+00:00","author":"\u6e05, \u5b87","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u5b87"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/","name":"\u4f7f\u7528Ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-04-18T23:21:01+00:00","dateModified":"2024-01-15T00:16:25+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528Ruby\u521b\u5efa\u53ef\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e","name":"\u6e05, \u5b87","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","caption":"\u6e05, \u5b87"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ruby%e5%88%9b%e5%bb%ba%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/34398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=34398"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/34398\/revisions"}],"predecessor-version":[{"id":57700,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/34398\/revisions\/57700"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=34398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=34398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=34398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}