PHP code example of iwai / phalcon-session-adapter-cachebackend

1. Go to this page and download the library: Download iwai/phalcon-session-adapter-cachebackend library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iwai / phalcon-session-adapter-cachebackend example snippets


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;
});

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;
});

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