{"id":1344,"date":"2018-10-03T02:10:17","date_gmt":"2018-10-02T17:10:17","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=1344"},"modified":"2019-03-25T18:26:57","modified_gmt":"2019-03-25T09:26:57","slug":"%e6%b0%b8%e4%b9%85%e4%bf%9d%e5%ad%98%e7%89%88%ef%bc%81laravel%e3%83%bbcache%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9%e5%a4%a7%e5%85%a8","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=1344","title":{"rendered":"\u6c38\u4e45\u4fdd\u5b58\u7248\uff01Laravel\u30fbCache\u306e\u4f7f\u3044\u65b9\u5927\u5168"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u958b\u767a\u3067\u30da\u30fc\u30b8\u8868\u793a\u306e\u901f\u5ea6\u3092\u5411\u4e0a\u3055\u305b\u308b\u305f\u3081\u306b\u3088\u304f\u300c\u30ad\u30e3\u30c3\u30b7\u30e5\u300d\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u30ad\u30e3\u30c3\u30b7\u30e5\u3068\u306f\u3001<strong>\u6642\u9593\u304c\u304b\u304b\u308b\u8a08\u7b97\u7d50\u679c\u3092\u4e00\u6642\u7684\u306b\u4fdd\u7ba1\u3057\u3066\u304a\u3044\u3066\u3001\u4e00\u5b9a\u6642\u9593\u306f\u91cd\u305f\u3044\u51e6\u7406\u3092\u7701\u7565\u3059\u308b<\/strong>\u30c6\u30af\u30cb\u30c3\u30af\u3067\u3059\u304c\u3001Laravel\u3067\u306f\u3053\u306e\u300c\u30ad\u30e3\u30c3\u30b7\u30e5\u300d\u304c\u3068\u3066\u3082\u7c21\u5358\u306b\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306a\u3063\u3066\u3044\u307e\u3059\u3002\uff08\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u3082\u3063\u3068\u8a73\u3057\u3044\u8aac\u660e\u306f<a href=\"#about_cache\">\u3053\u3061\u3089<\/a>\uff09<\/p>\n<p>\u305f\u3060\u3057\u3001Laravel\u306b\u306f\u591a\u304f\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u6a5f\u80fd\u304c\u3042\u308b\u305f\u3081\u3001\u5c11\u3057\u982d\u304c\u8907\u96d1\u306b\u611f\u3058\u308b\u3053\u3068\u3082\u3042\u3063\u305f\u308a\u3059\u308b\u306e\u3082\u4e8b\u5b9f\u3067\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u4eca\u56de\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u6a5f\u80fd\u306b\u3064\u3044\u3066\u307e\u3068\u3081\u305f\u300c\u5927\u5168\u300d\u7684\u306a\u8a18\u4e8b\u3092\u516c\u958b\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<br \/>\n\u305c\u3072\u958b\u767a\u306e\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u203b \u5b9f\u884c\u74b0\u5883\u306f\u3001Laravel 5.7\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-417 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9.png\" alt=\"\" width=\"370\" height=\"220\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9-300x178.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<h1>\u304a\u6025\u304e\u306e\u4eba\u5411\u3051\uff08\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u4fdd\u5b58\uff06\u53d6\u5f97\uff09<\/h1>\n<p>Laravel\u3067\u30b7\u30f3\u30d7\u30eb\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u6271\u3044\u305f\u3044\u5834\u5408\u306f\u30d8\u30eb\u30d1\u30fc\u95a2\u6570<code>cache()<\/code>\u3092\u4f7f\u3046\u3068\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<pre>\/\/ 10\u5206\u9593\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u4fdd\u5b58\r\n<strong>cache(['key' =&gt; '\u4fdd\u5b58\u30c7\u30fc\u30bf'], 10);<\/strong><\/pre>\n<pre>\/\/ \u53d6\u5f97\r\n<strong>$cache = cache('key');<\/strong><\/pre>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4fdd\u5b58\u3057\u305f\u3044<\/h1>\n<h2 id=\"put_in_minutes\">\u6709\u52b9\u6642\u9593\uff08\u5206\uff09\u3092\u6307\u5b9a\u3057\u3066\u4fdd\u5b58<\/h2>\n<p>\u4f8b\u3048\u3070\u30011\u6642\u9593\uff08=60\u5206\u9593\uff09\u6709\u52b9\u306a\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>$minutes = 10; \/\/ \u6709\u52b9\u671f\u9593\uff08\u5206\uff09\r\n<strong>\\Cache::put('key', '\u4fdd\u5b58\u30c7\u30fc\u30bf', $minutes);<\/strong><\/pre>\n<p>\u203b \u3061\u306a\u307f\u306b\u3001<code>$minutes<\/code>\u306e\u6570\u3092<code>0<\/code>\u306b\u3059\u308b\u3068\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u4fdd\u5b58\u3055\u308c\u307e\u305b\u3093\u3002\uff08\u4ee5\u524d\u306f\u6709\u52b9\u671f\u9650\u304c\u306a\u3044\u30ad\u30e3\u30c3\u30b7\u30e5\u3068\u3057\u3066\u4fdd\u5b58\u3055\u308c\u3066\u3044\u307e\u3057\u305f\uff09<\/p>\n<p>\u3010\u6ce8\u610f\u3011<\/p>\n<p>\u30d3\u30b8\u30bf\u30fc\u3055\u3093\u304b\u3089\u306e\u6307\u6458\u3067\u6c17\u3065\u304d\u307e\u3057\u305f\u304c\u3001<strong>Laravel 5.8\u304b\u3089\u306f\u300c\u5206\u300d\u3067\u306f\u306a\u304f\u300c\u79d2\u300d\u3067\u306e\u6307\u5b9a\u306b\u5909\u66f4\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/strong>\uff08\u672c\u5bb6\u306e\u8aac\u660e\u306f<a href=\"https:\/\/laravel-news.com\/cache-ttl-change-coming-to-laravel-5-8\" target=\"_blank\" rel=\"noopener noreferrer\">\u3053\u3061\u3089<\/a>\uff09\u30b5\u30f3\u30d7\u30eb\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<pre>$seconds = 600; \/\/ \u6709\u52b9\u671f\u9593\uff08\u79d2\uff09\u300210\u5206\u3002\r\n<strong>\\Cache::put('key', '\u4fdd\u5b58\u30c7\u30fc\u30bf', $seconds);<\/strong><\/pre>\n<p>\u3053\u308c\u3063\u3066\u7d50\u69cb\u5927\u304d\u306a\u5909\u66f4\u3067\u3059\u3088\u306d^^;<br \/>\n\u308f\u3056\u308f\u3056\u9023\u7d61\u3092\u304f\u3060\u3055\u3063\u3066\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\uff01<\/p>\n<h2>\u6709\u52b9\u6642\u9593\uff08\u79d2\uff09\u3092\u6307\u5b9a\u3057\u3066\u4fdd\u5b58<\/h2>\n<p>Laravel 5.8\u304b\u3089\u306f\u300c\u5206\u300d\u3067\u306f\u306a\u304f\u300c\u79d2\u300d\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u6642\u9593\u3092\u6307\u5b9a\u3059\u308b\u3088\u3046\u5909\u66f4\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u8a73\u3057\u304f\u306f<a href=\"#put_in_minutes\">\u6709\u52b9\u6642\u9593\uff08\u5206\uff09\u3092\u6307\u5b9a\u3057\u3066\u4fdd\u5b58<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u6709\u52b9\u671f\u9650\uff08\u65e5\u6642\uff09\u3092\u6307\u5b9a\u3057\u3066\u4fdd\u5b58<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u4eca\u304b\u308915\u5206\u5f8c\u307e\u3067\u6709\u52b9\u306a\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>$dt = now()-&gt;addMinutes(15);<\/strong> \/\/ 15\u5206\u5f8c\r\n\\Cache::put('key', '\u4fdd\u5b58\u30c7\u30fc\u30bf', <strong>$dt<\/strong>);<\/pre>\n<h2>\u6709\u52b9\u671f\u9650\u304c\u306a\u3044\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4fdd\u5b58<\/h2>\n<pre><strong>\\Cache::forever('key', '\u4fdd\u5b58\u30c7\u30fc\u30bf');<\/strong><\/pre>\n<h2>\u3082\u3057\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u306a\u3044\u306a\u3089\u4fdd\u5b58\u3057\u305f\u3044<\/h2>\n<p>\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u306a\u3051\u308c\u3070\u3001\u4fdd\u5b58\u3092\u3057\u305f\u3044\u5834\u5408\u306f<code>add()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre>$minutes = 10;\r\n\\Cache::<strong>add('key', '\u65b0\u3057\u3044\u30c7\u30fc\u30bf', $minutes);<\/strong><\/pre>\n<p>\u203b \u3082\u3057\u3059\u3067\u306b<code>key<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u3042\u308b\u5834\u5408\u306f\u4f55\u3082\u8d77\u3053\u308a\u307e\u305b\u3093\u3002<br \/>\n\u203b \u6709\u52b9\u671f\u9650\u304c\u5207\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u65b0\u3057\u3044\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001<code>add()<\/code>\u306f\u300c\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u4f5c\u6210\u3055\u308c\u305f\uff1f\u300d\u304c\u5206\u304b\u308b\u3088\u3046\u306b\u3001<code>true<\/code>\/<code>false<\/code>\u304c\u8fd4\u3057\u3066\u304f\u308c\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u30b3\u30fc\u30c9\u306e\u5207\u308a\u66ff\u3048\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre>$minutes = 10;\r\n<strong>$result<\/strong> = \\Cache::add('key', '\u65b0\u3057\u3044\u30c7\u30fc\u30bf', $minutes);\r\n\r\nif(<strong>$result<\/strong>) {\r\n\r\n    echo '\u65b0\u3057\u3044\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002';\r\n\r\n}<\/pre>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u547c\u3073\u51fa\u3057\u305f\u3044<\/h1>\n<p>\u3059\u3067\u306b\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u304b\u3089\u30c7\u30fc\u30bf\u3092\u547c\u3073\u51fa\u3059\u306b\u306f<code>get()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<h2>\u57fa\u672c\u5f62<\/h2>\n<pre>$cache = <strong>\\Cache::get('key')<\/strong>;<\/pre>\n<h2>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6307\u5b9a\u3057\u3066\u53d6\u5f97<\/h2>\n<p>\u6709\u52b9\u671f\u9650\u304c\u3042\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u6642\u9593\u304c\u6765\u308b\u3068\u524a\u9664\u3055\u308c\u3066\u3057\u307e\u3046\u305f\u3081\u3001\u30c7\u30fc\u30bf\u304c\u3044\u3064\u3067\u3082\u53d6\u5f97\u3067\u304d\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u306e\u305f\u3081\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306b\u4f7f\u3046\u300c\u4ee3\u308f\u308a\u306e\u30c7\u30fc\u30bf\u300d\u3092\u3042\u3089\u304b\u3058\u3081\u6307\u5b9a\u3057\u3066\u304a\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>$cache = \\Cache::get('key', <strong>'\u4ee3\u308f\u308a\u306e\u30c7\u30fc\u30bf'<\/strong>);<\/pre>\n<p>\u203b \u3082\u3057<code>key<\/code>\u3068\u3044\u3046\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u306a\u3051\u308c\u3070<code>$cache<\/code>\u306f\u300c\u4ee3\u308f\u308a\u306e\u30c7\u30fc\u30bf\u300d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>function\u3092\u4f7f\u3063\u305f\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6307\u5b9a\u3057\u3066\u53d6\u5f97<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u65e5\u66dc\u65e5\u3060\u3051\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u5207\u308a\u66ff\u3048\u305f\u3044\u5834\u5408\u306f<code>function<\/code>\u3092\u4f7f\u3046\u3068\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<pre>$cache = \\Cache::get('key', <strong>function(){\r\n\r\n    if(today()-&gt;isSunday()) {\r\n\r\n        return '\u65e5\u66dc\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024';\r\n\r\n    }\r\n\r\n    return '\u305d\u306e\u4ed6\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024';\r\n\r\n}<\/strong>);<\/pre>\n<h2>\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u547c\u3073\u51fa\u3057\u3066\u3001\u3059\u3050\u524a\u9664\u3057\u305f\u3044<\/h2>\n<p>\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3001\u3059\u3050\u305d\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u6d88\u3057\u305f\u3044\u5834\u5408\u306f\u3001<code>pull()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre>$cache = <strong>\\Cache::pull('key')<\/strong>;   \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u524a\u9664\u3055\u308c\u307e\u3059<\/pre>\n<p>\u306a\u304a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>$cache = \\Cache::pull('key', <strong>'\u30c7\u30d5\u30a9\u30eb\u30c8\u5024'<\/strong>);<\/pre>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664\u3057\u305f\u3044<\/h1>\n<h2>\u7279\u5b9a\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664\u3057\u305f\u3044<\/h2>\n<pre><strong>\\Cache::forget('key'); \/\/ \u300ckey\u300d\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3060\u3051\u524a\u9664<\/strong><\/pre>\n<h2>\u5168\u3066\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664\u3057\u305f\u3044<\/h2>\n<pre><strong>\\Cache::flush(); \/\/ \u5168\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664<\/strong><\/pre>\n<h1>\u81ea\u52d5\u66f4\u65b0\uff08\u4f5c\u6210\uff09\u3059\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u3064\u304f\u308a\u305f\u3044<\/h1>\n<p><code>put()<\/code>\u3084<code>add()<\/code>\u3092\u4f7f\u3048\u3070\u3001\u6c17\u8efd\u306b\u5909\u6570\u5185\u306e\u30c7\u30fc\u30bf\u3092\u30ad\u30e3\u30c3\u30b7\u30e5\u5316\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u6bce\u56de<code>has()<\/code>\u30e1\u30bd\u30c3\u30c9\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3001\u3082\u3057\u306a\u3051\u308c\u3070\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f5c\u6210\u3059\u308b\u3068\u3044\u3046\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u306e\u306f\u3081\u3093\u3069\u3046\u3060\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u5834\u5408\u306b\u4f7f\u3048\u308b\u306e\u304c<code>remember()<\/code>\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u4f8b\u306f10\u5206\u3054\u3068\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u66f4\u65b0\u3059\u308b\uff08\u3064\u307e\u308a\u300110\u5206\u9593\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u6709\u52b9\u306b\u306a\u308b\uff09\u4f8b\u3067\u3059\u3002<\/p>\n<pre>$minutes = 10;\r\n$cache = <strong>\\Cache::remember('key', $minutes, function(){<\/strong>\r\n\r\n<strong>    return now()-&gt;toDateTimeString(); \/\/ 10\u5206\u3054\u3068\u306b\u81ea\u52d5\u66f4\u65b0<\/strong>\r\n\r\n<strong>});<\/strong><\/pre>\n<p>\u307e\u305f\u3001\u6709\u52b9\u6642\u9593\u3092\u6c7a\u3081\u306a\u3044\u5834\u5408\u306f\u3001<code>rememberForever()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u304c\u3001\u3053\u3061\u3089\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u624b\u52d5\u3067\u6d88\u3055\u308c\u308b\u307e\u3067\u66f4\u65b0\u3055\u308c\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<pre>$cache = \\Cache::<strong>rememberForever<\/strong>('key', function(){\r\n\r\n    return now()-&gt;toDateTimeString();\r\n\r\n});<\/pre>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u5b58\u5728\u3059\u308b\u304b\u30c1\u30a7\u30c3\u30af\u3057\u305f\u3044<\/h1>\n<p>\u4f8b\u3048\u3070\u3001<code>key<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u3042\u308b\u304b\uff08\u6709\u52b9\u671f\u9650\u304c\u304d\u308c\u3066\u3044\u306a\u3044\u304b\uff09\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>if(<strong>\\Cache::has('key')<\/strong>) {\r\n\r\n    echo '\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u898b\u3064\u304b\u308a\u307e\u3057\u305f\u3002';\r\n\r\n}<\/pre>\n<h1 id=\"switch_cache\">\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u6cd5\u3092\u5207\u308a\u66ff\u3048\u305f\u3044<\/h1>\n<p>Laravel\u3067\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u65b9\u5f0f\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3060\u3051\u3067\u306f\u306a\u304f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u65b9\u5f0f\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u7ba1\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>apc<\/li>\n<li>array \u203b<a href=\"#array_cache\">array\u65b9\u5f0f\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u3064\u3044\u3066<\/a><\/li>\n<li>database<\/li>\n<li>file\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\uff09<\/li>\n<li>memcached<\/li>\n<li>redis<\/li>\n<\/ul>\n<div><\/div>\n<p>\u305d\u3057\u3066\u3001\u52d5\u7684\u306b\u3053\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3092\u5909\u66f4\u3057\u305f\u3044\u5834\u5408\u306f<code>store()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002\u4ee5\u4e0b\u306f<code>apc<\/code>\u65b9\u5f0f\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4fdd\u5b58\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<pre>\\Cache::<strong>store('apc')<\/strong>-&gt;put('key', '\u4fdd\u5b58\u30c7\u30fc\u30bf', 10);<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3092\u5909\u66f4\u3057\u305f\u3044\u5834\u5408\u306f<code>.env<\/code>\u5185\u306e<code>CACHE_DRIVER<\/code>\u3067\u8a2d\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u5b9f\u969b\u306b\u306f\u3053\u306e\u8a2d\u5b9a\u304c<code>\/config\/cache.php<\/code>\u306e\u4e2d\u3067\u53cd\u6620\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\uff09<\/p>\n<h1>\u6570\u5b57\u3092\u3069\u3093\u3069\u3093\u5897\u3084\u3057\u305f\u3044\uff0f\u6e1b\u3089\u3057\u305f\u3044<\/h1>\n<h2>\u6570\u5b57\u3092\u3069\u3093\u3069\u3093\u5897\u3084\u3057\u305f\u3044<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u8868\u793a\u56de\u6570\u3092\u30ab\u30a6\u30f3\u30c8\u3057\u3066\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u4fdd\u5b58\u3057\u3066\u304a\u304d\u305f\u3044\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>\\Cache::increment('key');<\/strong>\r\necho \\Cache::get('key'); \/\/ 1\u304b\u3089\u3069\u3093\u3069\u3093\u5897\u3048\u3066\u3044\u304f<\/pre>\n<p>\u3082\u3057\u5897\u3084\u3059\u6570\u5b57\u3092\u5909\u3048\u305f\u3044\u5834\u5408\u306f\u7b2c\uff12\u5f15\u6570\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>\\Cache::increment('key', <strong>100<\/strong>); \/\/ 100\u305a\u3064\u5897\u3048\u308b<\/pre>\n<h2>\u6570\u5b57\u3092\u3069\u3093\u3069\u3093\u6e1b\u3089\u3057\u305f\u3044<\/h2>\n<p>\u9006\u306b\u6570\u5b57\u3092\u3069\u3093\u3069\u3093\u6e1b\u3089\u3057\u3066\u3044\u304d\u305f\u3044\u5834\u5408\u306f\u3001<code>decrement()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>\\Cache::decrement('key');<\/strong> \/\/ 1\u305a\u3064\u6e1b\u308b<\/pre>\n<p>\u3082\u3061\u308d\u3093\u3001\u7b2c\uff12\u5f15\u6570\u306f\u6e1b\u3089\u3059\u6570\u5024\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>\\Cache::decrement('key', <strong>100<\/strong>); \/\/ 100\u305a\u3064\u6e1b\u308b<\/pre>\n<h2>\u3082\u3068\u3082\u3068\u9055\u3046\u578b\u306e\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3044\u305f\u3089\uff1f\uff1f<\/h2>\n<p>\u4e00\u65e6\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u4e2d\u8eab\u304c\u30bc\u30ed\uff08\u6570\u5024\uff09\u306b\u306a\u308a\u3001\u305d\u3053\u304b\u3089<code>increment()<\/code>\u3082\u3057\u304f\u306f<code>decrement()<\/code>\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><strong>\\Cache::put('key', '\u30c7\u30fc\u30bf', 10); \/\/ \u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\r\n\\Cache::increment('key');\r\necho \\Cache::get('key'); \/\/ \u300c1\u300d\u306b\u306a\u308a\u307e\u3059\u3002<\/strong><\/pre>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u30bf\u30b0\u3092\u4f7f\u3044\u305f\u3044<\/h1>\n<p><strong>\u6ce8\u610f\uff1a<\/strong> \u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30bf\u30b0\u3092\u4f7f\u3046\u5834\u5408\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u304c\u4ee5\u4e0b\u306e\u3082\u306e\u3067\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u3002<\/p>\n<ul>\n<li>apc<\/li>\n<li>array<\/li>\n<li>memcached<\/li>\n<li>redis<\/li>\n<\/ul>\n<p>\u305d\u306e\u305f\u3081\u3001\u4eca\u56de\u306f<code>.env<\/code>\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>apc<\/code>\u3092\u4f7f\u3046\u3088\u3046\u5909\u66f4\u3057\u3066\u5b9f\u884c\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre>CACHE_DRIVER=<strong>apc<\/strong><\/pre>\n<h2>\u30bf\u30b0\u3092\u3064\u3051\u3066\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4fdd\u5b58\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u30b3\u30ab\u30fb\u30b3\u30fc\u30e9\u306b\u300c\u70ad\u9178\u98f2\u6599\u300d\u3068\u300c\u9ed2\u300d\u3068\u3044\u3046\u30bf\u30b0\u3092\u3064\u3051\u3066\u4fdd\u5b58\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>\\Cache::<strong>tags(['\u70ad\u9178\u98f2\u6599', '\u9ed2'])<\/strong>-&gt;put('coke', '\u30b3\u30ab\u30fb\u30b3\u30fc\u30e9', $minutes);<\/pre>\n<h2>\u30bf\u30b0\u3092\u6307\u5b9a\u3057\u3066\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u540c\u3058\u3088\u3046\u306b\u30bf\u30b0\u3092\u6307\u5b9a\u3057\u3066<code>get()<\/code>\u3059\u308b\u3060\u3051\u3067OK\u3067\u3059\u3002<\/p>\n<pre>$cache = \\Cache::<strong>tags(['\u70ad\u9178\u98f2\u6599', '\u9ed2'])<\/strong>-&gt;get('coke'); \/\/ \u30b3\u30ab\u30fb\u30b3\u30fc\u30e9<\/pre>\n<p>\u305f\u3060\u3057\u3001\u53d6\u5f97\u306e\u969b\u306b\u6c17\u3092\u3064\u3051\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u304c\u3001<strong>tags()\u306b\u306f\u4fdd\u5b58\u6642\u3068\u540c\u3058\u5185\u5bb9\u3067\u3001\u3057\u304b\u3082\u540c\u3058\u4e26\u3073\u3067\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3068\u3044\u3046\u3053\u3068<\/strong>\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<pre>\\Cache::tags(['\u70ad\u9178\u98f2\u6599', '\u9ed2'])-&gt;put('coke', '\u30b3\u30ab\u30fb\u30b3\u30fc\u30e9', 10);\r\n\r\n<strong>\/\/ \u5168\u3066\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093<\/strong>\r\n<strong>echo \\Cache::tags(['\u70ad\u9178\u98f2\u6599'])-&gt;get('coke');<\/strong>\r\n<strong>echo \\Cache::tags(['\u9ed2'])-&gt;get('coke');<\/strong>\r\n<strong>echo \\Cache::tags(['\u9ed2', '\u70ad\u9178\u98f2\u6599'])-&gt;get('coke');<\/strong><\/pre>\n<p>\u500b\u4eba\u7684\u306b\u306f\u30bf\u30b0\u3068\u3044\u3046\u304b\u3089\u306b\u306f\u3001\u3072\u3068\u3064\u3067\u3082\u8a72\u5f53\u3059\u308b\u3082\u306e\u304c\u3042\u308c\u3070\u30c7\u30fc\u30bf\u53d6\u5f97\u3057\u3066\u307b\u3057\u3044\u306e\u3067\u3059\u304c\u3001\u73fe\u5728\u306e\u4f7f\u7528\u3067\u306f\u305d\u306e\u3088\u3046\u306b\u306f\u306a\u3063\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\u307e\u305f\u3001<strong>\u30bf\u30b0\u4ed8\u304d\u3067\u4fdd\u5b58\u3057\u305f\u30c7\u30fc\u30bf\u306f\u30bf\u30b0\u4ed8\u304d\u3067\u3057\u304b\u30c7\u30fc\u30bf\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3002<\/strong>\u3064\u307e\u308a\u3001\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u30c7\u30fc\u30bf\u306f\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<pre><strong>\\Cache::tags(['\u70ad\u9178\u98f2\u6599', '\u9ed2'])-&gt;put('coke', '\u30b3\u30ab\u30fb\u30b3\u30fc\u30e9', 10);<\/strong>\r\n<strong>echo \\Cache::get('coke');<\/strong> \/\/ \u30bf\u30b0\u306a\u3057\u306a\u306e\u3067\u3001\u53d6\u5f97\u3067\u304d\u306a\u3044\uff01<\/pre>\n<h2>\u30bf\u30b0\u4ed8\u304d\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664<\/h2>\n<p>\u30bf\u30b0\u304c\u4ed8\u3051\u3089\u308c\u305f\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664\u3059\u308b\u306b\u306f<code>flush()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre>\\Cache::tags(['\u70ad\u9178\u98f2\u6599', '\u9ed2'])-&gt;flush();<\/pre>\n<p>\u3053\u3053\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u306a\u306e\u304c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u4f8b\u3067\u3059\u3002<\/p>\n<pre>\\Cache::tags(<strong>['\u70ad\u9178\u98f2\u6599', '\u9ed2']<\/strong>)-&gt;put('coke', '\u30b3\u30ab\u30fb\u30b3\u30fc\u30e9', 10);\r\n\\Cache::tags(<strong>['\u70ad\u9178\u98f2\u6599', '\u900f\u660e']<\/strong>)-&gt;put('cider', '\u4e09\u30c4\u77e2\u30b5\u30a4\u30c0\u30fc', 10);\r\n\\Cache::tags(<strong>['\u30a8\u30ca\u30b8\u30fc\u30c9\u30ea\u30f3\u30af', '\u9ec4\u8272']<\/strong>)-&gt;put('red-bull', '\u30ec\u30c3\u30c9\u30d6\u30eb', 10);\r\n\r\n<strong>\\Cache::tags(['\u70ad\u9178\u98f2\u6599'])-&gt;flush();<\/strong>\r\necho \\Cache::tags(['\u70ad\u9178\u98f2\u6599', '\u9ed2'])-&gt;get('coke'); \/\/ \u53d6\u5f97\u3067\u304d\u306a\u3044\uff01\r\necho \\Cache::tags(['\u70ad\u9178\u98f2\u6599', '\u900f\u660e'])-&gt;get('cider'); \/\/ \u53d6\u5f97\u3067\u304d\u306a\u3044\uff01\r\necho \\Cache::tags(['\u30a8\u30ca\u30b8\u30fc\u30c9\u30ea\u30f3\u30af', '\u9ec4\u8272'])-&gt;get('red-bull'); \/\/ \u53d6\u5f97\u3067\u304d\u308b<\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001<code>flush()<\/code>\u3067\u300c\u70ad\u9178\u98f2\u6599\u300d\u3068\u3044\u3046\u30bf\u30b0\u304c\u4ed8\u3044\u3066\u3044\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u81ea\u4f53\u304c\u524a\u9664\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u300c\u30b3\u30ab\u30fb\u30b3\u30fc\u30e9\u300d\u3068\u300c\u4e09\u30c4\u77e2\u30b5\u30a4\u30c0\u30fc\u300d\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<h1>\u69d8\u3005\u306a\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3092\u4f7f\u3044\u305f\u3044<\/h1>\n<h2>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f7f\u3063\u305f\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f7f\u3044\u305f\u3044<\/h2>\n<p>\u307e\u305a\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan make:migration create_cache_table<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>\/database\/migrations<\/code>\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u3001<code>****_**_**_******_create_cache_table.php<\/code>\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3053\u308c\u3092\u958b\u3044\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002\uff08\u5909\u66f4\u3059\u308b\u5834\u6240\u306f\u592a\u5b57\u306e\u3068\u3053\u308d\uff09<\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Support\\Facades\\Schema;\r\nuse Illuminate\\Database\\Schema\\Blueprint;\r\nuse Illuminate\\Database\\Migrations\\Migration;\r\n\r\nclass CreateCacheTable extends Migration\r\n{\r\n    \/**\r\n     * Run the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function up()\r\n    {\r\n<strong>        Schema::create('cache', function (Blueprint $table) {<\/strong>\r\n<strong>            $table-&gt;string('key')-&gt;unique();<\/strong>\r\n<strong>            $table-&gt;text('value');<\/strong>\r\n<strong>            $table-&gt;integer('expiration');<\/strong>\r\n<strong>        });<\/strong>\r\n    }\r\n\r\n    \/**\r\n     * Reverse the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function down()\r\n    {\r\n        Schema::dropIfExists('cache');\r\n    }\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan migrate<\/strong><\/pre>\n<p>\u3053\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u5185\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30c6\u30fc\u30d6\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1351\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/cache_table_example.png\" alt=\"\" width=\"344\" height=\"457\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/cache_table_example.png 344w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/cache_table_example-226x300.png 226w\" sizes=\"auto, (max-width: 344px) 100vw, 344px\" \/><\/p>\n<p>\u5f8c\u306f\u3001<code>.env<\/code>\u306e<code>CACHE_DRIVER<\/code>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>database<\/code>\u3078\u5909\u66f4\u3059\u308c\u3070\u6e96\u5099\u306f\u5b8c\u4e86\u3002<\/p>\n<pre>CACHE_DRIVER=<strong>database<\/strong><\/pre>\n<p>\u203b \u5b9f\u969b\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u3092DB\u3078\u4fdd\u5b58\u3057\u305f\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1352\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/cache_table_example_2.png\" alt=\"\" width=\"534\" height=\"271\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/cache_table_example_2.png 534w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/cache_table_example_2-300x152.png 300w\" sizes=\"auto, (max-width: 534px) 100vw, 534px\" \/><\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u3088\u308a\u8a73\u3057\u3044\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30fb\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u8a2d\u5b9a\u3092\u3057\u305f\u3044\u5834\u5408\u306f<code>\/config\/cache.php<\/code>\u306e\u4e2d\u3067\u5909\u66f4\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>'database' =&gt; [\r\n    <strong>'driver' =&gt; 'database',<\/strong>\r\n<strong>    'table' =&gt; 'cache',<\/strong>\r\n<strong>    'connection' =&gt; null,<\/strong>\r\n],<\/pre>\n<h2>apc\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f7f\u3044\u305f\u3044<\/h2>\n<p><code>apc<\/code>\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f7f\u3046\u306b\u306f\u3001PHP\u306bapc(u)\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\uff08\u5b9f\u884c\u74b0\u5883\uff1a Ubuntu 18.04\uff09<\/p>\n<pre><strong>sudo apt install php-apcu<\/strong><\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\uff08apache, nginx\u306a\u3069\uff09\u3092\u518d\u8d77\u52d5\u3057\u3066<code>phpinfo()<\/code>\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308c\u3070\u6210\u529f\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1358\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/apc_phpinfo.png\" alt=\"\" width=\"960\" height=\"322\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/apc_phpinfo.png 960w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/apc_phpinfo-300x101.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/apc_phpinfo-768x258.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u5f8c\u306f\u3001<code>.env<\/code>\u306e<code>CACHE_DRIVER<\/code>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>apc<\/code>\u3078\u5909\u66f4\u3059\u308c\u3070\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<pre>CACHE_DRIVER=<b>apc<\/b><\/pre>\n<h2>memcached\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f7f\u3044\u305f\u3044<\/h2>\n<p>Laravel\u3067<code>memcached<\/code>\u3092\u4f7f\u3046\u5834\u5408\u306f\u3001PECL\u306ememcached\u304c\u5fc5\u8981\u306a\u306e\u3067\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002\uff08\u5b9f\u884c\u74b0\u5883\u306fUbuntu 18.04\uff09<\/p>\n<pre>sudo pecl install memcached<\/pre>\n<p>\u3082\u3057\u3001<code>error: memcached support requires libmemcached<\/code>\u3068\u3044\u3046\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u5834\u5408\u306f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u8db3\u308a\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30de\u30f3\u30c9\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>sudo apt install libmemcached-dev libmemcached<\/pre>\n<p>PELC\u3067memcached\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001php.ini\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e9\u30a4\u30f3\u3092\u8ffd\u52a0\u3057\u3066\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\uff08apache\u3084nginx\uff09\u3092\u518d\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>extension=memcached.so<\/strong><\/pre>\n<p><code>phpinfo()<\/code>\u3067<code>memcached<\/code>\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308c\u3070\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u6210\u529f\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1355\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/memcached_php_ini.png\" alt=\"\" width=\"973\" height=\"521\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/memcached_php_ini.png 973w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/memcached_php_ini-300x161.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/memcached_php_ini-768x411.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001<code>memcached<\/code>\u672c\u4f53\u3082\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>sudo apt install memcached<\/strong><\/pre>\n<p>\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067<code>memcached<\/code>\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>sudo systemctl start memcached<\/strong><\/pre>\n<p>\u5f8c\u306f\u3001<code>.env<\/code>\u306e<code>CACHE_DRIVER<\/code>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>memcached<\/code>\u3078\u5909\u66f4\u3059\u308c\u3070\u5b8c\u4e86\u3002<\/p>\n<pre>CACHE_DRIVER=<strong>memcached<\/strong><\/pre>\n<p><code>memcached<\/code>\u306e\u8a2d\u5b9a\u306f<code>\/config\/cache.php<\/code>\u5185\u3067\u5909\u66f4\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>'memcached' =&gt; [\r\n    <strong>'driver' =&gt; 'memcached',<\/strong>\r\n<strong>    'persistent_id' =&gt; env('MEMCACHED_PERSISTENT_ID'),<\/strong>\r\n<strong>    'sasl' =&gt; [<\/strong>\r\n<strong>        env('MEMCACHED_USERNAME'),<\/strong>\r\n<strong>        env('MEMCACHED_PASSWORD'),<\/strong>\r\n<strong>    ],<\/strong>\r\n<strong>    'options' =&gt; [<\/strong>\r\n<strong>        \/\/ Memcached::OPT_CONNECT_TIMEOUT  =&gt; 2000,<\/strong>\r\n<strong>    ],<\/strong>\r\n<strong>    'servers' =&gt; [<\/strong>\r\n<strong>        [<\/strong>\r\n<strong>            'host' =&gt; env('MEMCACHED_HOST', '127.0.0.1'),<\/strong>\r\n<strong>            'port' =&gt; env('MEMCACHED_PORT', 11211),<\/strong>\r\n<strong>            'weight' =&gt; 100,<\/strong>\r\n<strong>        ],<\/strong>\r\n<strong>    ],<\/strong>\r\n],<\/pre>\n<h2>redis\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f7f\u3044\u305f\u3044<\/h2>\n<p><code>redis<\/code>\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002\uff08\u5b9f\u884c\u74b0\u5883\uff1a Ubuntu 18.04\uff09<\/p>\n<p>\u307e\u305a\u306f<code>redis<\/code>\u672c\u4f53\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u8d77\u52d5\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre><strong>sudo apt install redis-server<\/strong><\/pre>\n<pre><strong>sudo systemctl start redis-server<\/strong><\/pre>\n<p>\u6b21\u306bPHP\u306e<code>redis<\/code>\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u3059\u3002<\/p>\n<pre><strong>sudo apt install php-redis<\/strong><\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\uff08apache, nginx\u306a\u3069\uff09\u3092\u518d\u8d77\u52d5\u3057\u3066<code>phpinfo()<\/code>\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308c\u3070\u6210\u529f\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1356\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/redit_phpinfo.png\" alt=\"\" width=\"963\" height=\"120\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/redit_phpinfo.png 963w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/redit_phpinfo-300x37.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/redit_phpinfo-768x96.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u3055\u3089\u306b\u3001Laravel\u3067<code>redis<\/code>\u3092\u4f7f\u3046\u5834\u5408\u306f<code>predis\/predis<\/code>\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u5fc5\u8981\u306a\u306e\u3067\u3001\u3053\u308c\u3082<code>composer<\/code>\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>composer require predis\/predis<\/strong><\/pre>\n<p>\u203b \u3061\u306a\u307f\u306b\u3001\u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u5fd8\u308c\u308b\u3068<code>Class 'Predis\\Client' not found<\/code>\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<p>\u5f8c\u306f\u3001<code>.env<\/code>\u306e<code>CACHE_DRIVER<\/code>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>redis<\/code>\u3078\u5909\u66f4\u3059\u308c\u3070\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<pre>CACHE_DRIVER=<b>redis<\/b><\/pre>\n<p>\u3082\u3057\u8a73\u3057\u3044\u8a2d\u5b9a\u3092\u3057\u305f\u3044\u5834\u5408\u306f\u3001<code>\/config\/cache.php<\/code>\u5185\u3067\u5909\u66f4\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>'redis' =&gt; [\r\n    <strong>'driver' =&gt; 'redis',<\/strong>\r\n<strong>    'connection' =&gt; 'cache',<\/strong>\r\n],<\/pre>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30a4\u30d9\u30f3\u30c8\u3092\u4f7f\u3044\u305f\u3044<\/h1>\n<p>Laravel\u3067\u4f7f\u3048\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u95a2\u9023\u306e\u30a4\u30d9\u30f3\u30c8\u306f\u4ee5\u4e0b\u306e\uff14\u3064\u3067\u3059\u3002<\/p>\n<ul>\n<li>LogCacheHit\u3000\u30fb\u30fb\u30fb\u3000\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30c7\u30fc\u30bf\u304c\u53d6\u5f97\u3055\u308c\u305f\u6642<\/li>\n<li>CacheMissed\u3000\u30fb\u30fb\u30fb\u3000\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u898b\u3064\u304b\u3089\u306a\u304b\u3063\u305f\u6642<\/li>\n<li>LogKeyForgotten\u3000\u30fb\u30fb\u30fb\u3000\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u524a\u9664\u3055\u308c\u305f\u6642<\/li>\n<li>LogKeyWritten\u3000\u30fb\u30fb\u30fb\u3000\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u66f8\u304d\u8fbc\u307e\u308c\u305f\u6642<\/li>\n<\/ul>\n<p>\u305f\u3060\u3057\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u30a4\u30d9\u30f3\u30c8\u30fb\u30ea\u30b9\u30ca\u30fc\u306f\u3042\u308a\u307e\u305b\u3093\u306e\u3067\u81ea\u5206\u3067\u4f5c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u5404\u30a4\u30d9\u30f3\u30c8\u306b\u5bfe\u5fdc\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u30fb\u30ea\u30b9\u30ca\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre>php artisan make:listener <strong>LogCacheHit<\/strong><\/pre>\n<pre>php artisan make:listener <strong>LogCacheMissed<\/strong><\/pre>\n<pre>php artisan make:listener <strong>LogKeyForgotten<\/strong><\/pre>\n<pre>php artisan make:listener <strong>LogKeyWritten<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u5404\u30ea\u30b9\u30ca\u30fc\u306e\u4e2d\u3067\u306f<code>handle()<\/code>\u30e1\u30bd\u30c3\u30c9\u5185\u3067\u8a72\u5f53\u3059\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u3053\u3053\u3067\u69d8\u3005\u306a\u51e6\u7406\u3092\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>public function handle(<strong>$event<\/strong>)\r\n{\r\n    <strong>$cache_key = $event-&gt;key;<\/strong> \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u30ad\u30fc\r\n    <strong>$cache_value = $event-&gt;value;<\/strong> \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u30c7\u30fc\u30bf\r\n    <strong>$cache_tags = $event-&gt;tags;<\/strong> \/\/ \u30bf\u30b0\uff08\u914d\u5217\uff09\r\n    <strong>$cache_minutes = $event-&gt;minutes;<\/strong> \/\/ \u6709\u52b9\u6642\u9593\r\n}<\/pre>\n<p>\u203b \u305f\u3060\u3057\u3001<code>LogCacheMissed<\/code>\u3068<code>LogKeyForgotten<\/code>\u306b\u306f<code>value<\/code>\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u307e\u305f\u3001<code>minutes<\/code>\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u306e\u306f<code>LogKeyWritten<\/code>\u306e\u307f\u3067\u3059\u3002<\/p>\n<p>\u5f8c\u306f\u3001\u4f5c\u6210\u3057\u305f\u30a4\u30d9\u30f3\u30c8\u30fb\u30ea\u30b9\u30ca\u30fc\u3092<code>\/app\/Providers\/EventServiceProvider.php<\/code>\u3067\u767b\u9332\u3059\u308c\u3070\u30a4\u30d9\u30f3\u30c8\u304c\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>protected $listen = [\r\n<strong>    'Illuminate\\Cache\\Events\\CacheHit' =&gt; [<\/strong>\r\n<strong>        \\App\\Listeners\\LogCacheHit::class,<\/strong>\r\n<strong>    ],<\/strong>\r\n\r\n<strong>    'Illuminate\\Cache\\Events\\CacheMissed' =&gt; [<\/strong>\r\n<strong>        \\App\\Listeners\\LogCacheMissed::class,<\/strong>\r\n<strong>    ],<\/strong>\r\n\r\n<strong>    'Illuminate\\Cache\\Events\\KeyForgotten' =&gt; [<\/strong>\r\n<strong>        \\App\\Listeners\\LogKeyForgotten::class,<\/strong>\r\n<strong>    ],<\/strong>\r\n\r\n<strong>    'Illuminate\\Cache\\Events\\KeyWritten' =&gt; [<\/strong>\r\n<strong>        \\App\\Listeners\\LogKeyWritten::class,<\/strong>\r\n<strong>    ],<\/strong>\r\n];<\/pre>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4e00\u6642\u7684\u306b\u30ed\u30c3\u30af\u3057\u305f\u3044<\/h1>\n<p>Laravel\u3067\u306f\u3001\u8ca0\u8377\u304c\u96c6\u4e2d\u3057\u306a\u3044\u76ee\u7684\u306a\u3069\u306e\u305f\u3081\u306b\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4e00\u6642\u7684\u306b\u4f7f\u3048\u306a\u3044\u3088\u3046\u30ed\u30c3\u30af\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><strong>\u203b \u6ce8\u610f\uff1a<\/strong> \u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30ed\u30c3\u30af\u306f<code>memcached<\/code>\u3068<code>redis<\/code>\u65b9\u5f0f\u306e\u307f\u6709\u52b9\u3067\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3067\u3059\u3002<\/p>\n<pre>$lock = <strong>\\Cache::lock('redis', 10)-&gt;get()<\/strong>;\r\n\r\nif($lock) {\r\n\r\n    echo '10\u79d2\u9593\u30ed\u30c3\u30af\u3092\u958b\u59cb\u3057\u307e\u3057\u305f\uff01';\r\n\r\n}<\/pre>\n<p>\u307e\u305f\u3001\u3082\u3046\u4e00\u3064\u306f<code>function<\/code>\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3067\u3001<code>function<\/code>\u306e\u51e6\u7406\u304c\u7d42\u4e86\u3059\u308b\u3068\u30ed\u30c3\u30af\u304c\u89e3\u9664\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre>\\Cache::lock('redis', 10)-&gt;get(<strong>function(){<\/strong>\r\n\r\n<strong>    sleep(5); \/\/ \u3053\u308c\u304c\u7d42\u308f\u308b\u3068\u30ed\u30c3\u30af\u89e3\u9664<\/strong>\r\n\r\n<strong>}<\/strong>);<\/pre>\n<p>\u3055\u3089\u306b\u3001<code>get()<\/code>\u3067\u306f\u306a\u304f<code>block()<\/code>\u3092\u4f7f\u3046\u3068\u6307\u5b9a\u3057\u305f\u6642\u9593\u30ed\u30c3\u30af\u306e\u89e3\u9664\u3092\u5f85\u305f\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>dd(<strong>\\Cache::lock('redis', 10)-&gt;block(7)<\/strong>);<\/pre>\n<p>\u3053\u306e\u4f8b\u3067\u306f\u300110\u79d2\u9593\u306e\u30ed\u30c3\u30af\u3092\u5b9f\u884c\u3057\u3001\u6700\u59277\u79d2\u9593\u89e3\u9664\u3055\u308c\u308b\u306e\u3092\u5f85\u3064\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u30663\u79d2\u3092\u8d85\u3048\u3066\u304b\u3089\u30ea\u30ed\u30fc\u30c9\u3059\u308b\u3068\uff17\u79d2\u9593\u306e\u5f85\u6a5f\u4e2d\u306b\u30ed\u30c3\u30af\u304c\u89e3\u9664\u3055\u308c\u308b\u306e\u3067\u3001\u51e6\u7406\u306f\u554f\u984c\u306a\u304f\u5b9f\u884c\u3067\u304d\u307e\u3059\u304c\u3001\uff13\u79d2\u4ee5\u5185\u306b\u30ea\u30ed\u30fc\u30c9\u3059\u308b\u3068\u5f85\u6a5f\u3059\u308b\u79d2\u6570\u304c\u8db3\u308a\u306a\u3044\u305f\u3081\u3001<code>LockTimeoutException<\/code>\u306e\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001<code>try\u301ccacth()<\/code>\u306a\u3069\u3067\u4f8b\u5916\u51e6\u7406\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u203b\u306a\u304a\u30012018\/10\/02\u73fe\u5728\u3001Laravel\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3067\u306fblockFor()\u3092\u4f7f\u3046\u3088\u3046\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u304c\u3001<code>Illuminate\\Cache\\Lock<\/code>\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u898b\u308b\u9650\u308a<code>block()<\/code>\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h1>\u72ec\u81ea\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30c9\u30e9\u30a4\u30d0\u30fc\u3092\u4f7f\u3044\u305f\u3044<\/h1>\n<p>Laravel\u306b\u306f\u59cb\u3081\u304b\u3089<a href=\"#switch_cache\">\u69d8\u3005\u306a\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059<\/a>\u304c\u3001\u3082\u3057\u304b\u3059\u308b\u3068\u5168\u304f\u7570\u306a\u3063\u305f\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3092\u4f7f\u3044\u305f\u3044\u5834\u5408\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u305d\u3093\u306a\u5834\u5408\u306b\u306f\u72ec\u81ea\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30c9\u30e9\u30a4\u30d0\u30fc\u3092\u81ea\u5206\u3067\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u30c6\u30b9\u30c8\u3068\u3057\u3066\u3001JSON\u30d5\u30a1\u30a4\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3059\u308b\u7c21\u6613\u7684\u306a\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30c9\u30e9\u30a4\u30d0\u30fc<code>json<\/code>\u3092\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u5b9f\u88c5\u30c6\u30b9\u30c8\u306a\u306e\u3067\u4f5c\u6210\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u306f<code>get()<\/code>\u3001<code>put()<\/code>\u3001<code>forget()<\/code>\u3001<code>flush()<\/code>\u306e\uff14\u3064\u3067\u3001\u6709\u52b9\u671f\u9650\u306e\u6a5f\u80fd\u306f\u7701\u7565\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3059\u308bJSON\u30d5\u30a1\u30a4\u30eb\u3092<code>\/storage\/app\/json\/cache.json<\/code>\u306b\u4f5c\u6210\u3057\u3001\u6a29\u9650\u3092\u5909\u3048\u3066\u66f8\u304d\u8fbc\u307f\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1362\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/Screenshot-from-2018-10-02-06-11-03.png\" alt=\"\" width=\"380\" height=\"139\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/Screenshot-from-2018-10-02-06-11-03.png 380w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/Screenshot-from-2018-10-02-06-11-03-300x110.png 300w\" sizes=\"auto, (max-width: 380px) 100vw, 380px\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001<code>\/config\/cache.php<\/code>\u306b<code>json<\/code>\u30c9\u30e9\u30a4\u30d0\u30fc\u3092\u8ffd\u52a0\u3057\u3001\u3055\u3089\u306b<code>.env<\/code>\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30c9\u30e9\u30a4\u30d0\u30fc\u3092\u540c\u3058\u304f<code>json<\/code>\u3078\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>'json' =&gt; [<\/strong>\r\n<strong>    'driver' =&gt; 'json'<\/strong>\r\n<strong>]<\/strong><\/pre>\n<pre>CACHE_DRIVER=<strong>json<\/strong><\/pre>\n<p>\u3055\u3089\u306b\u3001<code>\\app\\Extensions\\JsonStore.php<\/code>\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u4e2d\u3078\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Extensions;\r\n\r\nuse Illuminate\\Contracts\\Cache\\Store;\r\n\r\nclass JsonStore implements Store\r\n{\r\n    private $_json_path = '';\r\n    private $_json_data = [];\r\n\r\n    public function __construct()\r\n    {\r\n        $this-&gt;_json_path = storage_path('app\/json\/cache.json');\r\n        $this-&gt;_json_data = [];\r\n\r\n        if(file_exists($this-&gt;_json_path)) {\r\n\r\n            $this-&gt;_json_data = json_decode(\r\n                file_get_contents($this-&gt;_json_path),\r\n                true\r\n            );\r\n\r\n        }\r\n\r\n    }\r\n\r\n    public function <strong>get<\/strong>($key) {\r\n\r\n        return array_get($this-&gt;_json_data, $key);\r\n\r\n    }\r\n\r\n    public function <strong>put<\/strong>($key, $value, $minutes) {\r\n\r\n        $this-&gt;_json_data[$key] = $value;\r\n        $this-&gt;saveJson();\r\n\r\n    }\r\n\r\n    public function <strong>forget<\/strong>($key) {\r\n\r\n        if(array_has($this-&gt;_json_data, $key)) {\r\n\r\n            unset($this-&gt;_json_data[$key]);\r\n            $this-&gt;saveJson();\r\n\r\n        }\r\n\r\n    }\r\n\r\n    public function <strong>flush<\/strong>() {\r\n\r\n        $this-&gt;_json_data = [];\r\n        $this-&gt;saveJson();\r\n\r\n    }\r\n\r\n    private function saveJson() {\r\n\r\n        file_put_contents($this-&gt;_json_path, json_encode($this-&gt;_json_data));\r\n\r\n    }\r\n\r\n    \/\/ \u305d\u306e\u4ed6\uff08\u7701\u7565\u3067\u304d\u307e\u305b\u3093\uff09\r\n    public function many(array $keys) {}\r\n    public function putMany(array $values, $minutes) {}\r\n    public function increment($key, $value = 1) {}\r\n    public function decrement($key, $value = 1) {}\r\n    public function forever($key, $value) {}\r\n    public function getPrefix() {}\r\n\r\n}<\/pre>\n<p>\u203b \u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3001\u5358\u7d14\u306bJSON\u304b\u3089\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u66f8\u304d\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u6700\u5f8c\u306b\u3001\u3053\u306e<code>JsonStore<\/code>\u3092<code>AppServiceProvider<\/code>\u306e<code>boot()<\/code>\u5185\u3067\u767b\u9332\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>public function boot()\r\n{\r\n    <strong>\\Cache::extend('json', function ($app) {<\/strong>\r\n\r\n<strong>        return \\Cache::repository(<\/strong>\r\n<strong>            new \\App\\Extensions\\JsonStore()<\/strong>\r\n<strong>        );<\/strong>\r\n\r\n<strong>    });<\/strong>\r\n}<\/pre>\n<p>\u4ee5\u4e0a\u3067\u3001\u72ec\u81ea\u30c9\u30e9\u30a4\u30d0\u30fc\u304c\u5b9a\u7fa9\u3055\u308c\u307e\u3057\u305f\u3002\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u4fdd\u5b58\u3001\u53d6\u5f97\u3001\u524a\u9664\u306f\u4eca\u307e\u3067\u3068\u540c\u3058\u3067\u3059\u306e\u3067\u3001\u305c\u3072\u30c8\u30e9\u30a4\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1 id=\"about_cache\">\u305d\u3082\u305d\u3082\u30ad\u30e3\u30c3\u30b7\u30e5\u3068\u306f\uff1f\uff1f<\/h1>\n<p>\u4f8b\u3048\u3070\u3001Amazon\u306e\u3088\u3046\u306a\u7269\u8ca9\u30b5\u30a4\u30c8\u3067\u30a2\u30af\u30bb\u30b5\u30ea\u30fc\u90e8\u9580\u306e\u30e9\u30f3\u30ad\u30f3\u30b0\u7d50\u679c\u3092\u4f5c\u308b\u5834\u5408\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u624b\u9806\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3082\u306e\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u3042\u308b\u4e00\u5b9a\u671f\u9593\u306e\u5168\u3066\u306e\u6ce8\u6587\u30c7\u30fc\u30bf\u3092\u53d6\u5f97<\/li>\n<li>\u305d\u306e\u6ce8\u6587\u30c7\u30fc\u30bf\u3092\u58f2\u308c\u305f\u500b\u6570\u306a\u3069\u3067\u96c6\u8a08<\/li>\n<li>\u5546\u54c1\u306e\u4e26\u3079\u66ff\u3048\u3092\u3057\u3066\u3001\u30e9\u30f3\u30ad\u30f3\u30b0\u304c\u5b8c\u6210<\/li>\n<\/ol>\n<p>\u3053\u3053\u3067\u7279\u306b\u554f\u984c\u3068\u306a\u308b\u306e\u304c\uff12\u756a\u306e\u96c6\u8a08\u3092\u3059\u308b\u90e8\u5206\u3067\u3059\u3002\u30c7\u30fc\u30bf\u6570\u304c\u5c11\u306a\u3044\u306a\u3089\u3001\u96c6\u8a08\u306b\u305d\u308c\u307b\u3069\u6642\u9593\u306f\u304b\u304b\u308a\u307e\u305b\u3093\u304c\u3001Amazon\u306e\u3088\u3046\u306a\u5de8\u5927\u30b5\u30a4\u30c8\u3067\u306f\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u306e\u8ca0\u8377\u304c\u83ab\u5927\u306a\u3082\u306e\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u3001\u30a2\u30af\u30bb\u30b9\u304c\u3042\u308b\u5ea6\u306b\u30e9\u30f3\u30ad\u30f3\u30b0\u8a08\u7b97\u3059\u308b\u308f\u3051\u306b\u306f\u3044\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u3001\u3053\u308c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u6280\u8853\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u4eca\u56de\u306e\u4f8b\u3067\u8a00\u3046\u3068\u3001<\/p>\n<ul>\n<li>\u8a08\u7b97\u306b\u6642\u9593\u304c\u304b\u304b\u308b\u30e9\u30f3\u30ad\u30f3\u30b0\u7d50\u679c\u3092\u3059\u3050\u8aad\u307f\u8fbc\u3081\u308b\u4e00\u6642\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58<\/li>\n<li>\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u5b58\u5728\u3057\u3066\u3044\u308c\u3070\u30e9\u30f3\u30ad\u30f3\u30b0\u8a08\u7b97\u306f\u305b\u305a\u3001\u4fdd\u5b58\u3057\u305f\u7d50\u679c\u3092\u4f7f\u7528<\/li>\n<li>\u4e00\u5b9a\u6642\u9593\u3092\u8d85\u3048\u305f\u3089\u3053\u306e\u4e00\u6642\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664<\/li>\n<li>\u307e\u305f\u8a08\u7b97\u3092\u3057\u3066\u65b0\u3057\u3044\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f5c\u6210<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u624b\u9806\u3092\u3068\u308b\u3053\u3068\u3067\u3001\u6642\u9593\u304c\u304b\u304b\u308b\u8a08\u7b97\u3092\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u3067\u304d\u308b\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f5c\u6210\u3059\u308b\u306e\u306f\u5927\u91cf\u30c7\u30fc\u30bf\u306e\u8a08\u7b97\u90e8\u5206\u3060\u3051\u3067\u306f\u306a\u304f\u3001\u5148\u307b\u3069\u306e\uff11\u756a\u3067\u898b\u305f\u300c\u3042\u308b\u4e00\u5b9a\u671f\u9593\u306e\u6ce8\u6587\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u300d\u306e\u90e8\u5206\u3067\u3082\u5229\u7528\u3055\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u3044\u3064\u3082\u540c\u3058\u5185\u5bb9\u3092\u53d6\u5f97\u3059\u308b\u306e\u306b\u6bce\u56de\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306e\u306f\u8ca0\u8377\u304c\u304b\u304b\u308a\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u3053\u306e\u300c\u30c7\u30fc\u30bf\u53d6\u5f97\u300d\u90e8\u5206\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f5c\u3063\u3066\u304a\u3051\u3070\u9ad8\u901f\u5316\u304c\u671f\u5f85\u3067\u304d\u308b\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u3046\u307e\u304f\u5229\u7528\u3059\u308b\u3068\u30da\u30fc\u30b8\u8868\u793a\u306f\u5287\u7684\u306b\u65e9\u304f\u306a\u308a\u3001\u3055\u3089\u306b\u30b5\u30fc\u30d0\u30fc\u3078\u306e\u8ca0\u8377\u3082\u5c11\u306a\u304f\u306a\u308b\u306e\u3067\u4e00\u77f3\u4e8c\u9ce5\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3068\u8a00\u3048\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u30a2\u30af\u30bb\u30b9\u304c\u591a\u3044\u30b5\u30a4\u30c8\u306f\u305c\u3072\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u6d3b\u7528\u3057\u305f\u3044\u3067\u3059\u306d\uff01<\/p>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u4e0a\u66f8\u304d\u306b\u3064\u3044\u3066<\/h1>\n<p>\u307e\u3060\u6709\u52b9\u6642\u9593\u5185\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u3042\u308b\u5834\u5408\u306b\u3001<code>put()<\/code>\u306a\u3069\u3067\u65b0\u3057\u3044\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4fdd\u5b58\u3059\u308b\u5834\u5408\u306f\u3001<strong>\u6709\u52b9\u6642\u9593\u3092\u542b\u3081\u305f\u5168\u3066\u306e\u30c7\u30fc\u30bf\u304c\u4e0a\u66f8\u304d\u3055\u308c\u307e\u3059\u3002<\/strong><\/p>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u4fdd\u5b58\u3067\u304d\u308b\u30c7\u30fc\u30bf\uff08\u578b\uff09\u306f\uff1f<\/h1>\n<p>Laravel\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u4fdd\u5b58\u3067\u304d\u308b\u30c7\u30fc\u30bf\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u69d8\u3005\u306a\u578b\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u6587\u5b57\u5217<\/h2>\n<pre>\\Cache::forever('key', <b>'\u30c6\u30ad\u30b9\u30c8'<\/b>);<\/pre>\n<h2>\u6570\u5024<\/h2>\n<pre>\\Cache::forever('key', <b>1<\/b>);<\/pre>\n<h2>\u914d\u5217<\/h2>\n<pre>\\Cache::forever('key', <strong>['\u8d64', '\u9752', '\u9ec4\u8272']<\/strong>);<\/pre>\n<h2>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h2>\n<pre>\\Cache::forever('key', <strong>[<\/strong>\r\n<strong>    'red' =&gt; '\u8d64',<\/strong>\r\n<strong>    'blue' =&gt; '\u9752',<\/strong>\r\n<strong>    'yellow' =&gt; '\u9ec4\u8272'<\/strong>\r\n<strong>]<\/strong>);<\/pre>\n<h2>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9<\/h2>\n<pre>\\Cache::forever('key', <strong>new Carbon()<\/strong>);<\/pre>\n<h1>\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u4fdd\u5b58\u3055\u308c\u308b\u5834\u6240\u306f\uff1f\uff1f<\/h1>\n<p><code>file<\/code>\u65b9\u5f0f\uff08\u521d\u671f\u72b6\u614b\uff09\u306e\u5834\u5408\u3001<code>\/storage\/framework\/cache\/data<\/code>\u30d5\u30a9\u30eb\u30c0\u4ee5\u4e0b\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u3082\u3057\u6709\u52b9\u6642\u9593\u3064\u304d\u3067\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u305f\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5185\u5bb9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>1538293956s:12:\"\u30c6\u30ad\u30b9\u30c8\";<\/strong><\/pre>\n<h1 id=\"array_cache\">array\u65b9\u5f0f\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u3064\u3044\u3066<\/h1>\n<p><code>\/config\/cache.php<\/code>\u306e\u4e2d\u306b\u306f<code>array<\/code>\u3068\u3044\u3046\u65b9\u5f0f\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u9078\u629e\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>Laravel\u306e\u516c\u5f0f\u30b5\u30a4\u30c8\u3067\u306f\u3001<code>array<\/code>\u65b9\u5f0f\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u95a2\u3059\u308b\u8a73\u3057\u3044\u8aac\u660e\u3092\u898b\u3064\u3051\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u304c\u3001<code>Illuminate\\Cache\\ArrayStore<\/code>\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u898b\u308b\u9650\u308a\u3001\u3053\u306e\u65b9\u5f0f\u306f\u5b9f\u969b\u306b\u306f\u3069\u3053\u304b\u306b\u30c7\u30fc\u30bf\u4fdd\u5b58\u305b\u305a\u3001\u5358\u306b\u30c7\u30fc\u30bf\u3092\u914d\u5217\u306b\u683c\u7d0d\u3057\u3066\u3044\u308b\u3060\u3051\u306e\u3088\u3046\u3067\u3059\u3002\u3064\u307e\u308a\u3001\u30da\u30fc\u30b8\u8868\u793a\u5358\u4f4d\u3067\u30c7\u30fc\u30bf\u306f\u305d\u306e\u90fd\u5ea6\u6d88\u3048\u3066\u3057\u307e\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>public function put($key, $value, $minutes)\r\n{\r\n    <strong>$this-&gt;storage[$key] = $value;<\/strong>\r\n}<\/pre>\n<p>\u203b \u5b9f\u969b\u306b\u4e00\u65e6\u4fdd\u5b58\u3057\u305f\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u30ea\u30ed\u30fc\u30c9\u3057\u3066\u3082\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<h1>\u5b9f\u969b\u3001\u3069\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u304c\u9ad8\u901f\u3067\u3059\u304b\uff1f\uff1f<\/h1>\n<p><a href=\"#switch_cache\">\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3092\u5207\u308a\u66ff\u3048\u305f\u3044<\/a>\u3067\u3082\u66f8\u3044\u305f\u3068\u304a\u308a\u3001Laravel\u3067\u306f\u73fe\u5728\u306e\u3068\u3053\u308d\u4ee5\u4e0b\uff16\u3064\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>apc<\/li>\n<li>array \u203b<a href=\"#array_cache\">array\u65b9\u5f0f\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u3064\u3044\u3066<\/a><\/li>\n<li>database<\/li>\n<li>file<\/li>\n<li>memcached<\/li>\n<li>redis<\/li>\n<\/ul>\n<p>\u305f\u3060\u3001\u9ad8\u901f\u5316\u3092\u76ee\u7684\u3068\u3057\u305f\u5834\u5408\u306f\u4e00\u4f53\u3069\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u9078\u629e\u3059\u308b\u3079\u304d\u304b\u3092\u691c\u8a0e\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u691c\u8a3c\u65b9\u6cd5<\/h2>\n<p><a href=\"https:\/\/blog.capilano-fw.com\/?p=823\">Laravel 5.6\u306e\u9ad8\u901f\u5316\u691c\u8a3c\u30fbartisan\u30b3\u30de\u30f3\u30c9\uff13\u3064\u306e\u30ad\u30e3\u30c3\u30b7\u30e5<\/a>\u3067\u3082\u5229\u7528\u3057\u305f\u30eb\u30fc\u30d7\u3092\u4f7f\u3063\u305f\u65b9\u6cd5\u3067\u3001100\u4e07\u56de\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u8aad\u307f\u8fbc\u307f\uff0f\u66f8\u304d\u8fbc\u307f\u3092\u3055\u305b\u3001\u3088\u308a\u5c11\u306a\u3044\u6642\u9593\u3067\u5b8c\u4e86\u3067\u304d\u305f\u3082\u306e\u304c\u3082\u3063\u3068\u3082\u9ad8\u901f\u306a\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3068\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;?php \r\n\r\n$start = microtime(true);\r\n\r\nfor($i = 0 ; $i &lt; 100000 ; $i++) {\r\n\r\n    \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u66f8\u304d\u8fbc\u307f\u3084\u8aad\u307f\u8fbc\u307f\r\n\r\n}\r\n\r\n$time = microtime(true) - $start;\r\necho $time .'\u79d2';<\/pre>\n<p>\u3067\u306f\u3001\u307e\u305a\u306f\u8aad\u307f\u8fbc\u307f\u306e\u5b9f\u884c\u7d50\u679c\u304b\u3089\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u3082\u3063\u3068\u3082\u8aad\u307f\u8fbc\u307f\u304c\u65e9\u3044\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u306f\uff1f\uff1f<\/h2>\n<p>\u5b9f\u884c\u3059\u308b\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>$start = microtime(true);\r\n\r\n<strong>$cache = \\Cache::store('CACHE-TYPE'); <\/strong>\/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3092\u6307\u5b9a\r\n<strong>$cache-&gt;put('key', '\u4fdd\u5b58\u30c7\u30fc\u30bf');<\/strong>\r\n\r\nfor($i = 0 ; $i &lt; 100000 ; $i++) {\r\n\r\n    <strong>echo $cache-&gt;get('key');<\/strong>\r\n\r\n}\r\n\r\n$time = microtime(true) - $start;\r\necho $time .'\u79d2';<\/pre>\n<p>\u307e\u305a\u59cb\u3081\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3092\u5207\u308a\u66ff\u3048\u3066\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3001\u305d\u3057\u3066100\u4e07\u56de\u547c\u3073\u51fa\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u7d50\u679c\u3067\u3059\u3002<\/p>\n<ol>\n<li>array\u3000\u30fb\u30fb\u30fb\u3000<strong>0.14071893692017\u79d2<\/strong><\/li>\n<li>apc\uff08PHP 7.2\uff09\u3000\u30fb\u30fb\u30fb\u3000<strong>0.17040491104126\u79d2<\/strong><\/li>\n<li>file(SSD\u74b0\u5883) \u30fb\u30fb\u30fb\u3000<strong>1.6274020671844\u79d2<\/strong><\/li>\n<li>memcached\u3000\u30fb\u30fb\u30fb\u3000<strong>3.2162840366364\u79d2<\/strong><\/li>\n<li>redis\u3000\u30fb\u30fb\u30fb\u3000<strong>4.5471999645233\u79d2<\/strong><\/li>\n<li>database(MySQL 5.7) \u30fb\u30fb\u30fb\u3000<strong>29.163866996765\u79d2<\/strong><\/li>\n<\/ol>\n<p>\u3084\u306f\u308a\u3001\u5358\u7d14\u306b\u914d\u5217\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u3060\u3051\u306e<code>array<\/code>\u65b9\u5f0f\u304c\u65e9\u304b\u3063\u305f\u3067\u3059\u3002\u305f\u3060\u3001\u4e88\u60f3\u3068\u306f\u9055\u3063\u3066<code>apc<\/code>\u304c\u3068\u3066\u3082\u65e9\u304f\u5b9f\u884c\u3067\u304d\u305f\u306e\u3067\u9a5a\u304d\u307e\u3057\u305f\u3002\u306a\u304a\u3001\u671f\u5f85\u3057\u3066\u3044\u305f<code>memcached<\/code>\u3084<code>redis<\/code>\u306f<code>file<\/code>\u65b9\u5f0f\u3068\u6bd4\u3079\u3066\u3082\u3001\u305d\u308c\u307b\u3069\u9ad8\u901f\u5316\u3059\u308b\u308f\u3051\u3067\u306f\u306a\u304f\u3001DB\u306b\u81f3\u3063\u3066\u306f\u300c\u30fb\u30fb\u30fb\u300d\u3068\u3044\u3046\u7d50\u679c\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h2>\u3082\u3063\u3068\u3082\u66f8\u304d\u8fbc\u307f\u304c\u65e9\u3044\u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u306f\uff1f\uff1f<\/h2>\n<p>\u30b3\u30fc\u30c9\u306f\u3053\u3061\u3089\u3067\u3059\u3002<\/p>\n<pre>$start = microtime(true);\r\n<strong>$cache = \\Cache::store('CACHE-TYPE');<\/strong> \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u65b9\u5f0f\u3092\u6307\u5b9a\r\n\r\nfor($i = 0 ; $i &lt; 100000 ; $i++) {\r\n\r\n    <strong>$cache-&gt;put('key', '\u4fdd\u5b58\u30c7\u30fc\u30bf');<\/strong>\r\n\r\n}\r\n\r\n$time = microtime(true) - $start;\r\necho $time .'\u79d2';<\/pre>\n<p>\u3067\u306f\u7d50\u679c\u3067\u3059\u3002<\/p>\n<ol>\n<li>redis\u3000\u30fb\u30fb\u30fb\u3000<strong>0.016289949417114\u79d2<\/strong><\/li>\n<li>apc\uff08PHP 7.2\uff09\u3000\u30fb\u30fb\u30fb\u3000<strong>0.016727209091187\u79d2<\/strong><\/li>\n<li>database(MySQL 5.7) \u30fb\u30fb\u30fb\u3000<strong>0.016852140426636\u79d2<\/strong><\/li>\n<li>memcached\u3000\u30fb\u30fb\u30fb\u3000<strong>0.016862869262695\u79d2<\/strong><\/li>\n<li>file(SSD\u74b0\u5883) \u30fb\u30fb\u30fb\u3000<strong>0.017729043960571\u79d2<\/strong><\/li>\n<li>array\u3000\u30fb\u30fb\u30fb\u3000<strong>0.017874002456665\u79d2<\/strong><\/li>\n<\/ol>\n<p>\u66f8\u304d\u8fbc\u307f\u306b\u95a2\u3057\u3066\u306f\u3001\u307b\u307c\u5168\u3066\u304c\u6a2a\u4e26\u3073\u3068\u3044\u3046\u7d50\u679c\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u305d\u306e\u5dee\u306f\u308f\u305a\u304b\u306a\u306e\u3067\u3001\u30ea\u30ed\u30fc\u30c9\u3057\u3066\u307f\u308b\u3068\u9806\u4f4d\u304c\u5909\u308f\u3063\u3066\u3057\u307e\u3046\u5834\u5408\u3082\u3042\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u8aad\u307f\u8fbc\u307f\uff0f\u66f8\u304d\u8fbc\u307f\u3069\u3061\u3089\u306e\u691c\u8a3c\u3067\u3082\u4e0a\u4f4d\u3092\u30ad\u30fc\u30d7\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u4eca\u56de\u306e\u7d50\u679c\u3060\u3051\u307f\u308b\u3068<code>apc<\/code>\u65b9\u5f0f\u304c\u9ad8\u901f\u5316\u306b\u306f\u6709\u5229\u3068\u3044\u3046\u7d50\u679c\u306b\u306a\u308a\u307e\u3057\u305f\u3002\uff08\u305f\u3060\u3057\u3001\u3082\u3061\u308d\u3093\u74b0\u5883\u306b\u3088\u3063\u3066\u5909\u5316\u304c\u3042\u308b\u3067\u3057\u3087\u3046\uff09<\/p>\n<h1>cache()\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u306f\u3069\u306e\u3088\u3046\u306b\u4f7f\u3048\u307e\u3059\u304b\uff1f\uff1f<\/h1>\n<p>\u4eca\u56de\u306e\u8a18\u4e8b\u3067\u306f<code>\\Cache::get()<\/code>\u306e\u3088\u3046\u306bFacade\u3092\u4f7f\u3063\u305f\u8a18\u8ff0\u3092\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>cache()<\/code>\u3092\u4f7f\u3063\u3066\u7f6e\u304d\u63db\u3048\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre><strong>cache()-&gt;put('key', '\u30c7\u30fc\u30bf', 10);<\/strong> \/\/ \u4fdd\u5b58\r\n\r\nif(<strong>cache()-&gt;has('key')<\/strong>) { \/\/ \u5b58\u5728\u30c1\u30a7\u30c3\u30af\r\n\r\n    echo <strong>cache()-&gt;get('key'); <\/strong>\/\/ \u53d6\u5f97\r\n\r\n}<\/pre>\n<h1>\u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc<\/h1>\n<p>Laravel\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u95a2\u9023\u3067\u4e00\u756a\u3088\u304f\u8868\u793a\u3055\u308c\u308b\u30a8\u30e9\u30fc\u306f\u4ee5\u4e0b\u306e\u3082\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<pre><strong>file_put_contents(\/***\/storage\/framework\/cache\/data\/*****): failed to open stream: Permission denied<\/strong><\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001\u30d5\u30a9\u30eb\u30c0\uff08\u3082\u3057\u304f\u306f\uff09\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u66f8\u304d\u8fbc\u307f\u6a29\u9650\u304c\u306a\u3044\u3053\u3068\u304c\u539f\u56e0\u306a\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30de\u30f3\u30c9\u3067<code>storage<\/code>\u4ee5\u4e0b\u5168\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u5b9f\u884c\u6a29\u9650\u3092\u4e0e\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>sudo chmod -R 777 storage<\/strong><\/pre>\n<p>\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-444 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/16.png\" alt=\"\" width=\"370\" height=\"310\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/16.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/16-300x251.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u958b\u767a\u3067\u30da\u30fc\u30b8\u8868\u793a\u306e\u901f\u5ea6\u3092\u5411\u4e0a\u3055\u305b\u308b\u305f\u3081\u306b\u3088\u304f\u300c\u30ad\u30e3\u30c3\u30b7\u30e5\u300d\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002 \u30ad\u30e3\u30c3\u30b7\u30e5\u3068\u306f\u3001\u6642\u9593\u304c\u304b\u304b\u308b\u8a08\u7b97\u7d50\u679c\u3092\u4e00\u6642\u7684\u306b\u4fdd\u7ba1\u3057 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=1344\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u6c38\u4e45\u4fdd\u5b58\u7248\uff01Laravel\u30fbCache\u306e\u4f7f\u3044\u65b9\u5927\u5168&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":1379,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[90],"class_list":["post-1344","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-90"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/1344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1344"}],"version-history":[{"count":34,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/1344\/revisions"}],"predecessor-version":[{"id":3306,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/1344\/revisions\/3306"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/1379"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}