All pastes #966863 Raw Edit

Mine

public php v1 · immutable
·published 2008-04-02 01:38 UTC
rendered paste body
<?php		class Cache {		var $file;		var $expire;				/**		 * @return FALSE if cache is invalid		 * @param file $file cache file		 * @param int $expire number of seconds until cache dies		 */		function Cache($file, $expire)		{			//check if cache is valid			if(is_file($file) && is_writeable($file))			{				$this->file =& $file;			} else {				trigger_error("Cache is does not exist or is not writable");				return FALSE;			}						//get number of seconds till cache expires			$this->expire = $expire;		}				/**		 * @return FALSE if cache is not dead		 */		function IsExpired()		{			if(filemtime($this->file) > (time() - $this->expire))			{				return FALSE;			}		}				/**		 * @return FALSE on fail		 * @param mixed array $data		 */		function CreateCache($data)		{			$data = serialize($data);			$fp = fopen($this->file, 'w');			if(fwrite($fp, $data) === FALSE)			{				trigger_error("There was an error writing to the cache");				return FALSE;			}			fclose($fp);		}				/**		 * @return mixed associative array		 */		function ReadCache()		{			$results = unserialize(implode('', file($file)));			while($data = mysql_fetch_assoc($data))			{				$data[] = $results;			}						return $data;		}			}?>