Search code examples
lithium

Memcache, Mongodb or other Database storage for Lithium Sessions


I'm getting comfortable with the Lithium framework, and was wondering if there were any samples for using MongoDB or Memcache for Lithium Sessions. Would there need to be a new Session Adapter written?


Solution

  • One option is to set the session adapter to 'Php' in lithium and pass 'session.save_handler' => 'memcached' to the config options which will use the memcached extension's save handler to store sessions in memcache:

    Session::config(array(
        'default' => array(
            'adapter' => 'Php',
            'session.save_handler' => 'memcached',
            'session.save_path' => 'sess1:11211, sess2:11211'
        )
    ));
    

    http://php.net/manual/en/memcached.sessions.php

    I store sessions in MongoDb by using the 'Model' adapter (which is available on lab.lithify.me):

    Session::config(array(
        'default' => array(
            'adapter' => 'Model',
            'model' => 'app\models\Sessions',
            'name' => 'session'
        )
    ));
    

    http://lab.lithify.me/lab/extensions/view/a68f6ad626aaf7be37805f8e72f672e2