memcache 形式的缓存php 扩展需求

    1. 需要开启 php_memcache 扩展

    memcache 相关知识:http://www.hcoder.net/books/read_10090.html

    修改全局配置 phpGrace/config.php

    1. 'cache' => array(
    2. 'type' => 'memcache',
    3. //以下配置为memcache及redis类型缓存的必须设置
    4. 'host' => '127.0.0.1', //主机地址
    5. 'port' => '11211', //端口
    6. 'pre' => 'grace_' //缓存变量前缀
    7. )

    调用演示

    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. }

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