How to use memcached from codeigniter

前端 未结 4 1914
我寻月下人不归
我寻月下人不归 2021-02-05 17:48

How to use memcached from codeigniter, and how to store session data to memcached. Please help me.

Thanks

相关标签:
4条回答
  • 2021-02-05 18:26

    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.

    0 讨论(0)
  • 2021-02-05 18:40

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

    0 讨论(0)
  • 2021-02-05 18:44

    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

    0 讨论(0)
  • 2021-02-05 18:44
    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 讨论(0)
提交回复
热议问题