Beispiel #1
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);
 }
Beispiel #2
0
 public function setUp()
 {
     parent::setup();
     if (!extension_loaded('memcached') || !class_exists('\\Memcache')) {
         $this->markTestSkipped('The Memcache extension is not available.');
     }
     $adapter = new MemCache();
     $adapter->addServer('localhost', 11211);
     $this->cache = new Cache($adapter);
 }