13

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

Thanks

Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
noname.cs
  • 1,938
  • 4
  • 16
  • 25

4 Answers4

15

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

Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
Tom Schlick
  • 2,298
  • 18
  • 26
  • 1
    thanks alot about the library. I'm going to use memcached as main cache layer and use memcached to store session data. Have you ever use memcached to store session data? – noname.cs Jan 29 '10 at 02:54
  • no but i never thought of it. i dont think it would be too difficult to overload the session library to append add and delete to/from memcache before and after the queries that the session class normally uses. now that you mention this im going to tinker around at work doing this for our applications... good idea :) – Tom Schlick Jan 29 '10 at 03:34
  • fixed the link. sorry about that. had to change my github username a while back – Tom Schlick Apr 14 '11 at 04:29
  • 1
    How does this stand up to the native memcache driver -> http://codeigniter.com/user_guide/libraries/caching.html#memcached – Ben Jun 21 '12 at 17:20
3

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

Mancy
  • 319
  • 3
  • 5
1

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.

Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
0
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);
        }

    }
Limitless isa
  • 3,689
  • 36
  • 28