Beispiel #1
0
 /**
  * @param array $config
  * @throws \Exception
  */
 protected function __construct($config)
 {
     parent::__construct($config);
     $this->memcache = new \Memcache();
     /**
      * This is something tricky in PHP. If you use pconnect (p=persistent) the connection will remain open all the time.
      * This is not a bad thing since we're using the cache all the time (you don't turn off the light of the kitchen if you're running in and out, switching it too much would even consume more)
      * In memcache, the old but stable implementation in PHP of memcached the persistent connection works like charm
      * In memcached however there is a severe bug which leads to a memory leak. If you'd take over code from this class to implement memcached, DON'T use the persistent connect!
      */
     if (!isset($this->config["host"])) {
         // the default host for memcached localhost
         $this->config["host"] = "localhost";
     }
     if (!isset($this->config["port"])) {
         // the default port for memcached is 11211
         $this->config["port"] = 11211;
     }
     if (!$this->memcache->pconnect($this->config["host"], $this->config["port"])) {
         if (isset($this->config["log_dir"])) {
             $log_dir = rtrim($this->config["log_dir"], "/");
             $log = new Logger('cache');
             $log->pushHandler(new StreamHandler($log_dir . "/log_" . date('Y-m-d') . ".txt", Logger::CRITICAL));
             $log->addCritical("Could not connect to memcached.", $this->config);
         } else {
             /*
              * if we have no log directory, it's no use to throw a TDTException
              */
             throw new \Exception("No connection could be made to the memcache. Please check your given configuration.");
         }
     }
 }
Beispiel #2
0
 private function _createCacheInstance($type)
 {
     $config = array("system" => $type);
     $cache = Cache::getInstance($config);
     $this->assertInstanceOf('tdt\\cache\\Cache', $cache, "Could not construct {$type} instance");
     return $cache;
 }