sShortKey = $sPrefix.md5($sKey); $this->sFile = "$sCachePath$this->sShortKey.txt"; $this->sFileLock = "$this->sFile.lock"; $this->iCacheTime = $iCacheTime; } public function Check() { if (array_key_exists($this->sShortKey, self::$aCache) || file_exists($this->sFileLock)) { return true; } return (file_exists($this->sFile) && ($this->iCacheTime == -1 || time() - filemtime($this->sFile) <= $this->iCacheTime)); } public function Exists() { return (array_key_exists($this->sShortKey, self::$aCache)) || (file_exists($this->sFile) || file_exists($this->sFileLock)); } public function Set($vContents) { if (!file_exists($this->sFileLock)) { if (file_exists($this->sFile)) { copy($this->sFile, $this->sFileLock); } $oFile = fopen($this->sFile, 'w'); fwrite($oFile, serialize($vContents)); fclose($oFile); if (file_exists($this->sFileLock)) { unlink($this->sFileLock); } self::$aCache[$this->sShortKey] = $vContents; return true; } return false; } public function Get() { if (array_key_exists($this->sShortKey, self::$aCache)) { return self::$aCache[$this->sShortKey]; } else if (file_exists($this->sFileLock)) { self::$aCache[$this->sShortKey] = unserialize(file_get_contents($this->sFileLock)); return self::$aCache[$this->sShortKey]; } else { self::$aCache[$this->sShortKey] = unserialize(file_get_contents($this->sFile)); return self::$aCache[$this->sShortKey]; } } public function ReValidate() { touch($this->sFile); } } ?>