开发者

How to use memcached from codeigniter

开发者 https://www.devze.com 2022-12-18 02:31 出处:网络
How to use memcached from codeigniter, and how to store session data to memcached. Please h开发者_开发百科elp me.

How to use memcached from codeigniter, and how to store session data to memcached. Please h开发者_开发百科elp me.

Thanks


Here is the link to my memcached_library for codeigniter

http://github.com/tomschlick/memcached-library

let me know what you think and if you have any issues please raise them in the issues section of the github repository


Codeigniter V2.1.0 supports caching http://codeigniter.com/user_guide/libraries/caching.html#memcached


Here is an introduction to memcached and PHP:

enhance_php_session_management

As far as using memcached from CI, I imagine you would want to either add the caching code directly into your models, or from your Controllers you would want to check the cache before querying data from a model.


public function index()
    {
        // manual connection to Mamcache
        $memcache = new Memcache;
        $memcache->connect("localhost",11211);

        $data=$memcache->get("test_key");

        if($data){
            echo 'cache data:';
            var_dump($data);
        }else{
            $data=$this->db->query("SELECT count(*) as ca FROM table WHERE typ=1 ")->row();
            $memcache->set("test_key",$data,false,10); // 10 seconds
            echo 'real data:';
            var_dump($data);
        }

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号