コード例 #1
0
 /**
  * Calls the corresponding function in the block and executes the data retrieval function.
  * @return \SimpleXMLElement The XML data tree
  */
 public final function callMemcacheBlock()
 {
     $callback = $this->getCallback();
     $db = $this->getDatabase();
     $mem = new \System\Cache\Memcache\Memcache();
     $xml = null;
     if ($mem->keyExists($this->key)) {
         $xmlString = $mem->get($this->key);
         if ($xmlString) {
             //suppress warning here in case of malformed xml
             $xml = @simplexml_load_string($xmlString);
             if ($xml instanceof \SimpleXMLElement) {
                 return $xml;
             } else {
                 $errorLogger = \System\Log\ErrorLogger::getInstance();
                 $errorLogger->out('[MemcacheBlock] Could not read memcache key ' . $this->key . ' as XML. Regenerating.', \System\Log\LoggerLevel::LEVEL_WARNING);
             }
         }
     }
     if (is_callable($callback)) {
         $xml = call_user_func($callback, $this);
         $mem->store($this->key, $xml->asXML(), $this->timeout);
     } else {
         throw new \System\Error\Exception\InvalidMethodException('The given callback cannot be called. Does it exist and is it public?');
     }
     return $xml;
 }