缓存
缓存
系统默认采用文件缓存,可以改为 redis
缓存,修改 config/cache.php
配置 'default' => 'redis'
return [
'default' => 'file',
'adapters' => [
'file' => [
'handler' => function() {
return new FilesystemAdapter('', 0, runtime_path() . DS . 'cache');
}
],
'redis' => [
'handler' => function() {
return new RedisAdapter(Redis::connection()->client());
}
]
]
];
<h3 id="h3-u7F13u5B58"><a name="缓存" class="reference-link"></a><span class="header-link octicon octicon-link"></span>缓存</h3><p>系统默认采用文件缓存,可以改为 <code>redis</code> 缓存,修改 <code>config/cache.php</code> 配置 <code>'default' => 'redis'</code></p>
<pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code><span class="kwd">return</span><span class="pln"> </span><span class="pun">[</span></code></li><li class="L1"><code><span class="pln"> </span><span class="str">'default'</span><span class="pln"> </span><span class="pun">=></span><span class="pln"> </span><span class="str">'file'</span><span class="pun">,</span></code></li><li class="L2"><code><span class="pln"> </span><span class="str">'adapters'</span><span class="pln"> </span><span class="pun">=></span><span class="pln"> </span><span class="pun">[</span></code></li><li class="L3"><code><span class="pln"> </span><span class="str">'file'</span><span class="pln"> </span><span class="pun">=></span><span class="pln"> </span><span class="pun">[</span></code></li><li class="L4"><code><span class="pln"> </span><span class="str">'handler'</span><span class="pln"> </span><span class="pun">=></span><span class="pln"> </span><span class="kwd">function</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L5"><code><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">FilesystemAdapter</span><span class="pun">(</span><span class="str">''</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> runtime_path</span><span class="pun">()</span><span class="pln"> </span><span class="pun">.</span><span class="pln"> DS </span><span class="pun">.</span><span class="pln"> </span><span class="str">'cache'</span><span class="pun">);</span></code></li><li class="L6"><code><span class="pln"> </span><span class="pun">}</span></code></li><li class="L7"><code><span class="pln"> </span><span class="pun">],</span></code></li><li class="L8"><code><span class="pln"> </span><span class="str">'redis'</span><span class="pln"> </span><span class="pun">=></span><span class="pln"> </span><span class="pun">[</span></code></li><li class="L9"><code><span class="pln"> </span><span class="str">'handler'</span><span class="pln"> </span><span class="pun">=></span><span class="pln"> </span><span class="kwd">function</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L0"><code><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">RedisAdapter</span><span class="pun">(</span><span class="typ">Redis</span><span class="pun">::</span><span class="pln">connection</span><span class="pun">()-></span><span class="pln">client</span><span class="pun">());</span></code></li><li class="L1"><code><span class="pln"> </span><span class="pun">}</span></code></li><li class="L2"><code><span class="pln"> </span><span class="pun">]</span></code></li><li class="L3"><code><span class="pln"> </span><span class="pun">]</span></code></li><li class="L4"><code><span class="pun">];</span></code></li></ol></pre>