示例#1
0
 public function __construct()
 {
     $di = \Phalcon\Di::getDefault();
     $cache_driver = $di['cache_driver'];
     $pool = new \Stash\Pool($cache_driver);
     $pool->setNamespace(\FA\Cache::getSitePrefix('doctrine'));
     $this->_cache = $pool;
 }
示例#2
0
 /**
  * This function is defined by the SessionHandlerInterface and is for PHP's
  * internal use. It is called randomly based on the session.gc_divisor,
  * session.gc_probability and session.gc_lifetime settings, which should be
  * set according to the drivers used. Those with built in eviction
  * mechanisms will not need this functionality, while those without it will.
  * It is also possible to disable the built in garbage collection (place
  * gc_probability as zero) and call the "purge" function on the Stash\Pool
  * class directly.
  *
  * @param  int  $maxlifetime
  * @return bool
  */
 public function gc($maxlifetime)
 {
     return $this->pool->purge();
 }
示例#3
0
            $cache_driver = new \Stash\Driver\Memcache();
            $cache_driver->setOptions($cache_config['memcached']);
            break;
        case 'file':
            $cache_driver = new \Stash\Driver\FileSystem();
            $cache_driver->setOptions($cache_config['file']);
            break;
        default:
        case 'memory':
        case 'ephemeral':
            $cache_driver = new \Stash\Driver\Ephemeral();
            break;
    }
    // Register Stash as session handler if necessary.
    if (!$cache_driver instanceof \Stash\Driver\Ephemeral) {
        $pool = new \Stash\Pool($cache_driver);
        $pool->setNamespace(\FA\Cache::getSitePrefix('session'));
        $session = new \Stash\Session($pool);
        \Stash\Session::registerHandler($session);
    }
    return $cache_driver;
});
$di->set('cache', array('className' => '\\FA\\Cache', 'arguments' => array(array('type' => 'service', 'name' => 'cache_driver'), array('type' => 'parameter', 'value' => 'user'))));
// Register URL handler.
$di->setShared('url', array('className' => '\\FA\\Url', 'arguments' => array(array('type' => 'service', 'name' => 'config'), array('type' => 'service', 'name' => 'request'), array('type' => 'service', 'name' => 'dispatcher'))));
// Register session service.
$di->setShared('session', '\\FA\\Session');
// Register CSRF prevention security token service.
$di->setShared('csrf', array('className' => '\\FA\\Csrf', 'arguments' => array(array('type' => 'service', 'name' => 'session'))));
// Register view helpers.
$di->setShared('viewHelper', '\\FA\\Phalcon\\Service\\ViewHelper');
示例#4
0
 /**
  * @param string $cache_level
  * @return \Stash\Pool
  */
 public static function getCache($cache_level = 'user')
 {
     static $caches;
     static $cache_driver;
     if (!$caches) {
         $caches = array();
     }
     if (isset($caches[$cache_level])) {
         return $caches[$cache_level];
     }
     if (!$cache_driver) {
         $cache_driver = self::getCacheDriver();
     }
     $pool = new \Stash\Pool($cache_driver);
     $pool->setNamespace(self::getSitePrefix($cache_level));
     $caches[$cache_level] = $pool;
     return $pool;
 }
示例#5
0
 public function __construct(\Stash\Interfaces\DriverInterface $cache_driver, $cache_level = 'user')
 {
     $pool = new \Stash\Pool($cache_driver);
     $pool->setNamespace(self::getSitePrefix($cache_level));
     $this->_cache = $pool;
 }
示例#6
0
 /**
  * Creates the pools with user defined options
  *
  * @param \Silex\Application $app The silex app
  *
  * @return \Pimple $pools The pools in the pimple container
  */
 private static function createPools($app)
 {
     $pools = new \Pimple();
     foreach ($app['pools.options'] as $name => $options) {
         $pool = new \Stash\Pool(self::fetchDriver($options));
         $pool->setLogger(self::fetchLogger($app, $options));
         $pools[$name] = $pools->share(function () use($pool) {
             return $pool;
         });
     }
     return $pools;
 }
示例#7
0
 public function init()
 {
     $pool = new Stash\Pool();
     $pool->set('index', 'index');
     $pool - get('index');
 }