Exemple #1
0
function CacheAction($CacheId,$Action=3600,$Dir='') {

	$CacheId = trim($CacheId);
	$Res = false;

	if ($Action===TBS_CANCEL) { // Cancel cache save if any
		$this->_CacheFile = false;
	} elseif ($CacheId === '*') {
		if ($Action===TBS_DELETE) $Res = tbs_Cache_DeleteAll($Dir,$this->CacheMask);
	} else {
		$CacheFile = tbs_Cache_File($Dir,$CacheId,$this->CacheMask);
		if ($Action===TBS_CACHENOW) {
			$this->meth_Cache_Save($CacheFile,$this->Source);
		} elseif ($Action===TBS_CACHEGETAGE) {
			if (file_exists($CacheFile)) $Res = time()-filemtime($CacheFile);
		} elseif ($Action===TBS_CACHEGETNAME) {
			$Res = $CacheFile;
		} elseif ($Action===TBS_CACHEISONSHOW) {
			$Res = ($this->_CacheFile!==false);
		} elseif ($Action===TBS_CACHELOAD) {
			if (file_exists($CacheFile)) {
				if (tbs_Misc_GetFile($this->Source,$CacheFile)) {
					$this->_CacheFile = $CacheFile;
					$Res = true;
				}
			}
			if ($Res===false)	$this->Source = '';
		} elseif ($Action===TBS_DELETE) {
			if (file_exists($CacheFile)) $Res = @unlink($CacheFile);
		} elseif ($Action===TBS_CACHEONSHOW) {
			$this->_CacheFile = $CacheFile;
			@touch($CacheFile);
		} elseif($Action>=0) {
			$Res = tbs_Cache_IsValide($CacheFile,$Action);
			if ($Res) { // Load the cache
				if (tbs_Misc_GetFile($this->Source,$CacheFile)) {
					$this->_CacheFile = true; // Special value
					$this->Show();
				} else {
					$this->meth_Misc_Alert('CacheAction Method','Unable to read the file \''.$CacheFile.'\'.');
					$Res==false;
				}
				$this->_CacheFile = false;
			} else {
				// The result will be saved in the cache when the Show() method is called
				$this->_CacheFile = $CacheFile;
				@touch($CacheFile);
			}
		}
	}

	return $Res;

}
 function OnCommand($CacheId, $Action = 3600, $Dir = false)
 {
     $TBS =& $this->TBS;
     $CacheId = trim($CacheId);
     $Res = false;
     if ($Dir === false) {
         $Dir = $TBS->CacheDir;
     }
     if (!isset($this->CacheFile[$TBS->_Mode])) {
         $this->CacheFile[$TBS->_Mode] = false;
     }
     if ($Action === TBS_CACHECANCEL) {
         // Cancel cache save if any
         $this->CacheFile[$TBS->_Mode] = false;
     } elseif ($CacheId === '*' and $Action === TBS_CACHEDELETE) {
         $Res = tbs_Cache_DeleteAll($Dir, $TBS->CacheMask);
     } elseif ($Action === TBS_CACHEDELETEMASK) {
         $Res = tbs_Cache_DeleteAll($Dir, $CacheId);
     } else {
         $CacheFile = tbs_Cache_File($Dir, $CacheId, $TBS->CacheMask);
         if ($Action === TBS_CACHENOW) {
             $this->meth_Cache_Save($CacheFile, $TBS->Source);
         } elseif ($Action === TBS_CACHEGETAGE) {
             if (file_exists($CacheFile)) {
                 $Res = time() - filemtime($CacheFile);
             }
         } elseif ($Action === TBS_CACHEGETNAME) {
             $Res = $CacheFile;
         } elseif ($Action === TBS_CACHEISONSHOW) {
             $Res = $this->CacheFile[$TBS->_Mode] !== false;
         } elseif ($Action === TBS_CACHELOAD) {
             if (file_exists($CacheFile)) {
                 if ($TBS->f_Misc_GetFile($TBS->Source, $CacheFile)) {
                     $this->CacheFile[$TBS->_Mode] = $CacheFile;
                     $Res = true;
                 }
             }
             if ($Res === false) {
                 $TBS->Source = '';
             }
         } elseif ($Action === TBS_CACHEDELETE) {
             if (file_exists($CacheFile)) {
                 $Res = @unlink($CacheFile);
             }
         } elseif ($Action === TBS_CACHEONSHOW) {
             $this->CacheFile[$TBS->_Mode] = $CacheFile;
             @touch($CacheFile);
         } elseif ($Action >= 0) {
             $Res = tbs_Cache_IsValide($CacheFile, $Action);
             if ($Res) {
                 // Load the cache
                 if ($TBS->f_Misc_GetFile($TBS->Source, $CacheFile)) {
                     // Display cache contents
                     $this->ShowFromCache = true;
                     $TBS->Show();
                     $this->ShowFromCache = false;
                 } else {
                     $TBS->meth_Misc_Alert('CacheSystem plug-in', 'Unable to read the file \'' . $CacheFile . '\'.');
                     $Res == false;
                 }
                 $this->CacheFile[$TBS->_Mode] = false;
             } else {
                 // The result will be saved in the cache when the Show() method is called
                 $this->CacheFile[$TBS->_Mode] = $CacheFile;
                 @touch($CacheFile);
             }
         }
     }
     return $Res;
 }