public static function loadFromDiskCache($key)
 {
     if (!self::$diskCacheDisabled) {
         if (isset(wfConfig::$diskCache[$key])) {
             return wfConfig::$diskCache[$key];
         }
         $cacheFile = self::getCacheFile();
         if (is_file($cacheFile)) {
             //require($cacheFile); //will only require the file on first parse through this code. But we dynamically update the var and update the file with each get
             try {
                 $cont = @file_get_contents($cacheFile);
                 if (strpos($cont, '<?php') === 0) {
                     //"<?php die() XX"
                     $cont = substr($cont, strlen(self::$tmpFileHeader));
                     wfConfig::$diskCache = @unserialize($cont);
                     if (isset(wfConfig::$diskCache) && is_array(wfConfig::$diskCache) && isset(wfConfig::$diskCache[$key])) {
                         return wfConfig::$diskCache[$key];
                     }
                 }
                 //Else don't return a cached value because this is an old file without the php header so we're going to rewrite it.
             } catch (Exception $err) {
             }
             //file_get or unserialize may fail, so just fail quietly.
         }
     }
     $val = self::getDB()->querySingle("select val from " . self::table() . " where name='%s'", $key);
     if (self::$diskCacheDisabled) {
         return $val;
     }
     wfConfig::$diskCache[$key] = isset($val) ? $val : '';
     try {
         $bytesWritten = @file_put_contents($cacheFile, self::$tmpFileHeader . serialize(wfConfig::$diskCache), LOCK_EX);
     } catch (Exception $err2) {
     }
     if (!$bytesWritten) {
         self::$diskCacheDisabled = true;
     }
     return $val;
 }
Esempio n. 2
0
 public static function loadFromDiskCache($key)
 {
     if (!self::$diskCacheDisabled) {
         if (isset(wfConfig::$diskCache[$key])) {
             return wfConfig::$diskCache[$key];
         }
         $cacheFile = self::getCacheFile();
         if (is_file($cacheFile)) {
             //require($cacheFile); //will only require the file on first parse through this code. But we dynamically update the var and update the file with each get
             try {
                 wfConfig::$diskCache = @unserialize(@file_get_contents($cacheFile));
                 if (isset(wfConfig::$diskCache) && is_array(wfConfig::$diskCache) && isset(wfConfig::$diskCache[$key])) {
                     return wfConfig::$diskCache[$key];
                 }
             } catch (Exception $err) {
             }
             //file_get or unserialize may fail, so just fail quietly.
         }
     }
     $val = self::getDB()->querySingle("select val from " . self::table() . " where name='%s'", $key);
     if (self::$diskCacheDisabled) {
         return $val;
     }
     wfConfig::$diskCache[$key] = isset($val) ? $val : '';
     try {
         $bytesWritten = @file_put_contents($cacheFile, serialize(wfConfig::$diskCache), LOCK_EX);
     } catch (Exception $err2) {
     }
     if (!$bytesWritten) {
         self::$diskCacheDisabled = true;
     }
     return $val;
 }