예제 #1
0
 /**
  * Loads a cache file into a given instance.
  */
 public function loadCacheFile($fname)
 {
     $this->clearData();
     $str = file_get_contents($fname);
     if ($str === false) {
         error_log("[TagRegistry] could not read cache file '{$fname}'");
         return false;
     }
     try {
         $tarr = explode("\n", $str);
         foreach ($tarr as $tstr) {
             if (strlen($tstr) > 0) {
                 //tag meta info, parse accordingly
                 $tmi = Social_Dsl_TagMetaInfo::fromString($tstr);
                 //check timestamp
                 $fpath = $tmi->getHandlerSourceFile();
                 $modTime = filemtime($fpath);
                 //error_log("$fpath: modTime=$modTime, last=" . $tmi->getLastModified());
                 if ($modTime != $tmi->getLastModified()) {
                     error_log("[TagRegistry] file contents changed for '{$fpath}', deleting cache..");
                     $this->loadTagHandlerMetaInfo($path, true);
                     self::removeCacheFile();
                 }
                 $tns = $tmi->getTagNamespace();
                 if (!isset($this->m_tagMetaInfo[$tns])) {
                     $this->m_tagMetaInfo[$tns] = array();
                 }
                 $this->m_tagMetaInfo[$tns][$tmi->getTagName()] = $tmi;
             }
         }
     } catch (Exception $e) {
         error_log("[TagRegistry] problem reading cache file '{$fname}': " . $e->getMessage());
         return false;
     }
     return true;
 }