Beispiel #1
0
 public function register(Container $container)
 {
     $cid = $this->cid;
     $container[$cid] = $container->factory(function () use($cid, $container) {
         $get = function ($key, $default = null) use($container, $cid) {
             $key = $cid . '.' . $key;
             return $container->offsetExists($key) ? $container->offsetGet($key) : $default;
         };
         $adapterName = $get('adapter');
         switch ($adapterName) {
             case 'redis':
                 $adapter = new AdapterPureRedis(['host' => $get('host'), 'port' => $get('port'), 'timeout' => $get('timeout'), 'password' => $get('password'), 'dbIndex' => $get('dbIndex')]);
                 break;
             case 'file':
                 $adapter = new AdapterFile($get('dir'));
                 break;
             default:
                 $adapter = new AdapternotCache();
                 break;
         }
         foreach ($get('options', []) as $k => $v) {
             $adapter->setOption($k, $v);
         }
         return new Cache($adapter);
     });
 }
Beispiel #2
0
 /**
  * Create cache object
  *
  * @param $config \Centreon\Config The application configuration
  * @return \Desarrolla2\Cache\Cache
  */
 public static function load($config)
 {
     $cacheType = null;
     if ($config->get('cache', 'enabled')) {
         $cacheType = $config->get('cache', 'type');
     }
     switch ($cacheType) {
         case 'apc':
             $driver = new ApcCache();
             break;
         case 'memcache':
             $driver = new MemCache();
             foreach ($config->get('cache', 'servers') as $server) {
                 list($serverHost, $serverPort) = explode(':', $server);
                 $driver->addServer($serverHost, $serverPort);
             }
             break;
         case 'memcached':
             $driver = new Memcached();
             foreach ($config->get('cache', 'servers') as $server) {
                 list($serverHost, $serverPort) = explode(':', $server);
                 $driver->addServer($serverHost, $serverPort);
             }
             break;
         case null:
         default:
             $driver = new NotCache();
             break;
     }
     $ttl = $config->get('cache', 'ttl', 3600);
     $driver->setOption('ttl', $ttl);
     return new DesarrollaCache($driver);
 }