Exemple #1
0
 static function notExistCache($filePath, $exp_time = 0, $handleContent = false, $subDir = '')
 {
     self::$curentContent = '';
     self::$handleContent = $handleContent;
     if (!CACHE_ON) {
         //Nếu tắt chế độ cache
         return true;
     }
     if (MEMCACHE_ON) {
         //Nếu bật chế độ mem_cache
         if ($subDir != '') {
             $filePath = $subDir . '/' . $filePath;
         }
         self::$curentCacheFilePath = $filePath;
         self::$curentExpTime = $exp_time;
         if (isset($_GET['delscache']) && (int) $_GET['delscache'] == '1') {
             self::delCache($filePath);
             return true;
         }
         $s_content = eb_memcache::do_get("scache:{$filePath}");
         if ($s_content !== false) {
             if (DEBUG) {
                 self::$cNum++;
                 self::$pNum++;
                 if (class_exists('Module') && Module::$name != '') {
                     $module_name = Module::$name;
                 } else {
                     $module_name = "-- Enbac system";
                 }
                 $info = "<b>" . $module_name . "</b><br /><font color=red><b>" . self::$curentCacheFilePath . "</b></font><br /><b>Cache Time:</b> " . $exp_time . "s ";
                 if ($exp_time > 0) {
                     $info .= "<b> Expire:</b> {$exp_time} sec";
                 } else {
                     $info .= "<b> Expire:</b> forever";
                 }
                 self::$cacheFilesList .= "<li>" . $info . "</li>";
             }
             if (self::$handleContent) {
                 self::$curentContent = $s_content;
             } else {
                 echo $s_content;
             }
             return false;
         }
     } else {
         if ($subDir != '') {
             EClassApi::CheckDir(DIR_CACHE . 'html/' . $subDir . '/', MEMCACHE_ON);
             $filePath = $subDir . '/' . $filePath;
         } else {
             EClassApi::CheckDir(DIR_CACHE . 'html/', MEMCACHE_ON);
         }
         self::$curentCacheFilePath = DIR_CACHE . 'html/' . $filePath . '.html';
         self::$curentExpTime = $exp_time;
         if (isset($_GET['delscache']) && (int) $_GET['delscache'] == '1') {
             self::delCache($filePath);
             return true;
         }
         if (file_exists(self::$curentCacheFilePath)) {
             if ($exp_time > 0) {
                 $filemtime = filemtime(self::$curentCacheFilePath);
                 if (TIME_NOW > $filemtime + $exp_time) {
                     return true;
                 }
             } else {
                 $filemtime = 0;
             }
             if (DEBUG) {
                 self::$cNum++;
                 self::$pNum++;
                 if (class_exists('Module') && Module::$name != '') {
                     $module_name = Module::$name;
                 } else {
                     $module_name = "-- Enbac system";
                 }
                 $info = "<b>" . $module_name . "</b><br /><font color=red><b>" . self::$curentCacheFilePath . "</b></font><br /><b>Cache Time:</b> " . $exp_time . "s ";
                 $info .= "<b>Created:</b> " . date('d/m/Y H:i:s', $filemtime);
                 if ($exp_time > 0) {
                     $info .= "<b> Expire:</b> " . date('d/m/Y H:i:s', TIME_NOW + $exp_time);
                 } else {
                     $info .= "<b> Expire:</b> forever";
                 }
                 self::$cacheFilesList .= "<li>" . $info . "</li>";
             }
             if (self::$handleContent) {
                 self::$curentContent = file_get_contents(self::$curentCacheFilePath);
             } else {
                 echo file_get_contents(self::$curentCacheFilePath);
             }
             return false;
         }
     }
     return true;
 }