View Single Post
Old 11-11-2008, 04:44 PM  
Tjeezers
Webmaster
 
Tjeezers's Avatar
 
Industry Role:
Join Date: Mar 2007
Location: BP4L - NL/RO
Posts: 16,556
First Step - Create a php page called cache.php
and dump this code in it....

Code:
<?
/**
 * Cache - Output caching
 * @package Cache
 * @author degro
 * @copyright 2008 Harry Varwijk - AWMS-Network.com
 */
class Cache
{

	function Cache($path, $disable=false, $disable_output=false)
	{
		if(!is_dir($path))		trigger_error("Path is not directory!", E_USER_ERROR);
		if(!is_writable($path))	trigger_error("Path is not writable!", E_USER_ERROR);

		if(!in_array(substr($path,-1),array("\\","/"))) $path.="/";
		
		$this->path = $path;
		$this->disable = (bool)$disable;
		$this->disable_output = (bool)$disable_output;
		$this->stack = array();
		
		$this->output = null;
	}
	
	function _output($output)
	{
		$this->output = $output;
		if(!$this->disable_output) echo $output;
	}

	function _load($file,$time)
	{
		$filename = $this->path.$file;
		
		if($this->disable) return false;
		if(!file_exists($filename)) return false;
		
		$f = fopen($filename, "r");
		$fstat = fstat($f);
		fclose($f);

		if(time()-$fstat['mtime']>$time) return false;
		
		return file_get_contents($filename);
		
	}

	function _start($file,$time)
	{

		$data = $this->_load($file,$time);
		if($data===false)
		{
			$this->stack[count($this->stack)] = $file;
			ob_start();
			return count($this->stack);
		}
		
		$data = $this->_unpack($data);
		
		$this->_output($data['__output__']);
		
		return $data;
	}

	function _unpack($data)
	{
		return unserialize($data);
	}

	function _pack($data)
	{
		return serialize($data);
	}
	
	function save($file,$time,$data=array())
	{

		if($this->disable) return false;

		$time = (int)$time;
		if(!$file) trigger_error("n-am fisier", E_USER_ERROR);
		if($time<1) trigger_error("timpul trebuie sa fie mai mare de 0", E_USER_ERROR);
		
		if(count($this->stack) && $file == $this->stack[count($this->stack)-1])
		{
			$filename = $this->path.$file;
			
			$data['__output__'] = ob_get_contents();
			ob_end_clean();
	
			if(file_exists($filename) && !is_writable($filename)) trigger_error("eroare la scriere", E_USER_ERROR);
	
			$f = fopen($filename, 'w');
			fwrite($f, $this->_pack($data));
			fclose($f);
			
			$this->_output($data['__output__']);
			
			unset( $this->stack[count($this->stack)-1]);
			
			return false;
		}
		elseif( count($this->stack) &&  in_array($file,$this->stack) )
		{
			trigger_error("eroare la stack: ".$this->stack[count($this->stack)-1], E_USER_ERROR);
			exit;
		}
		else
		{
			$r = $this->_start($file,$time);
			if(is_int($r))
			{
				return $r;
			}
			else
			{
				for($i = 0;$i<count($data); $i++)
				{
					$data[$i] = $r[$i];
				}
				return false;
			}
		}
	
	}

}

?>
Wait a few moments for me to find the rest, it was like 5 months ago i did it, and it saved me a shitload of Gigs... Just make step 1 first... Be right back
Need cola and chocolate first
__________________
Enroll in the SWAG Affiliate Asian Live Cam Program and get 9 free quality linkbacks from my network!
Wanna see how old school I am? Look at this! All my Cam Review Sites are here!
Tjeezers is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote