redis 形式的缓存php 扩展需求

    1. 需要开启 php_memcache 扩展

    redis 相关知识:http://www.hcoder.net/books/read_10105.html

    修改全局配置 phpGrace/config.php

    1. 'cache' => array(
    2. 'type' => 'redis',
    3. 'host' => '127.0.0.1', //主机地址
    4. 'port' => '6379', //端口
    5. 'pre' => 'grace_' //缓存变量前缀
    6. )

    调用演示

    1. <?php
    2. class indexController extends grace{
    3. public function index(){
    4. $this->cache('test', 12, '__getData');
    5. p($this->test);
    6. }
    7.  
    8. public function __getData(){
    9. echo '无缓存,进行查询...<br />';
    10. $db = db('persons');
    11. $persons = $db->fetchAll();
    12. return $persons;
    13. }
    14.  
    15. public function t(){
    16. $this->removeCache('test', '12');
    17. }
    18.  
    19. public function t2(){
    20. $this->clearCache();
    21. }
    22. }

    原文: http://www.phpgrace.com/doc/info/316-5.html