redis 形式的缓存php 扩展需求
- 需要开启 php_memcache 扩展
redis 相关知识:http://www.hcoder.net/books/read_10105.html
修改全局配置 phpGrace/config.php
- 'cache' => array(
- 'type' => 'redis',
- 'host' => '127.0.0.1', //主机地址
- 'port' => '6379', //端口
- 'pre' => 'grace_' //缓存变量前缀
- )
- <?php
- class indexController extends grace{
- public function index(){
- $this->cache('test', 12, '__getData');
- p($this->test);
- }
- public function __getData(){
- echo '无缓存,进行查询...<br />';
- $db = db('persons');
- $persons = $db->fetchAll();
- return $persons;
- }
- public function t(){
- $this->removeCache('test', '12');
- }
- public function t2(){
- $this->clearCache();
- }
- }