iwai/phalcon-session-adapter-cachebackend

CacheBackend adapter for session.

0.1.0 2015-09-22 16:30 UTC

This package is not auto-updated.

Last update: 2024-11-19 05:18:43 UTC


README

CacheBackend adapter for session.

Install

{
    "require": {
        "iwai/phalcon-session-adapter-cachebackend": "*"
    }
}

Usage

Multiple backend

use Iwai\Phalcon\Session\Adapter\CacheBackend;
use Phalcon\Cache\Frontend\Data as FrontendData;

$app->getDI()->setShared('session', function () {
    $session = new CacheBackend();

    $backend = new \Phalcon\Cache\Multiple();

    $backend->push(new \Phalcon\Cache\Backend\Apc(
        new FrontendData([ 'lifetime' => 3600 ]),
        [ 'prefix' => 'cache' ]
    ));
    $backend->push(new \Phalcon\Cache\Backend\Memcached(
        new FrontendData([ 'lifetime' => 86400 ]),
        [ 'prefix' => 'cache', 'host' => 'localhost', 'port' => 11211 ]
    ));

    $session->setBackend($backend);
    $session->start();

    return $session;
});

Single backend

use Iwai\Phalcon\Session\Adapter\CacheBackend;
use \Phalcon\Cache\Frontend\Data as FrontendData;

$app->getDI()->setShared('session', function () use ($config) {
    $session = new CacheBackend();

    $backend = new \Phalcon\Cache\Backend\Memcached(
        new FrontendData([ 'lifetime' => 86400 ]), [
        'prefix' => 'cache',
        'host'   => 'localhost',
        'port'   => 11211
    ]);
        
    $session->setBackend($backend);
    $session->start();

    return $session;
});

In controller

$value = $this->session->get('key');

See Also

Phalcon Cache Document