URI based hash, for nginx compatability
This commit is contained in:
		
							parent
							
								
									91c06bd20e
								
							
						
					
					
						commit
						8e54831873
					
				@ -849,8 +849,8 @@ function _get_user() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$_cache_hash = null;
 | 
					 | 
				
			||||||
$_cache_memcache = false;
 | 
					$_cache_memcache = false;
 | 
				
			||||||
 | 
					$_cache_key = null;
 | 
				
			||||||
$_cache_filename = null;
 | 
					$_cache_filename = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function _cache_active() {
 | 
					function _cache_active() {
 | 
				
			||||||
@ -871,30 +871,27 @@ function _cache_log($text) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function _start_cache() {
 | 
					function _start_cache() {
 | 
				
			||||||
	global $_cache_hash, $_cache_memcache, $_cache_filename;
 | 
						global $_cache_memcache, $_cache_key, $_cache_filename;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(_cache_active()) {
 | 
						if(_cache_active()) {
 | 
				
			||||||
		$_cache_hash = md5($_SERVER["QUERY_STRING"]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if(CACHE_MEMCACHE) {
 | 
							if(CACHE_MEMCACHE) {
 | 
				
			||||||
			$_cache_memcache = new Memcache;
 | 
								$_cache_memcache = new Memcache;
 | 
				
			||||||
			$_cache_memcache->pconnect('localhost', 11211);
 | 
								$_cache_memcache->pconnect('localhost', 11211);
 | 
				
			||||||
			$zdata = $_cache_memcache->get($_cache_hash);
 | 
								$_cache_key = "uri:".$_SERVER["REQUEST_URI"];
 | 
				
			||||||
 | 
								$data = $_cache_memcache->get($_cache_key);
 | 
				
			||||||
			if(DEBUG) {
 | 
								if(DEBUG) {
 | 
				
			||||||
				$stat = $zdata ? "hit" : "miss";
 | 
									$stat = $zdata ? "hit" : "miss";
 | 
				
			||||||
				_cache_log(time() . " " . $_cache_hash . sprintf(" %-12s ", $stat) . $_SERVER["QUERY_STRING"] . "\n");
 | 
									_cache_log(time() . " " . sprintf(" %-4s ", $stat) . $_cache_key . "\n");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if($zdata) {
 | 
								if($data) {
 | 
				
			||||||
				header("Content-type: text/html");
 | 
									header("Content-type: text/html");
 | 
				
			||||||
				$data = @gzuncompress($zdata);
 | 
									print $data;
 | 
				
			||||||
				if($data) {
 | 
									exit;
 | 
				
			||||||
					print $data;
 | 
					 | 
				
			||||||
					exit;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(CACHE_DIR) {
 | 
							if(CACHE_DIR) {
 | 
				
			||||||
 | 
								$_cache_hash = md5($_SERVER["QUERY_STRING"]);
 | 
				
			||||||
			$ab = substr($_cache_hash, 0, 2);
 | 
								$ab = substr($_cache_hash, 0, 2);
 | 
				
			||||||
			$cd = substr($_cache_hash, 2, 2);
 | 
								$cd = substr($_cache_hash, 2, 2);
 | 
				
			||||||
			$_cache_filename = "data/$ab/$cd/$_cache_hash";
 | 
								$_cache_filename = "data/$ab/$cd/$_cache_hash";
 | 
				
			||||||
@ -934,15 +931,16 @@ function _start_cache() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function _end_cache() {
 | 
					function _end_cache() {
 | 
				
			||||||
	global $_cache_hash, $_cache_memcache, $_cache_filename;
 | 
						global $_cache_memcache, $_cache_key, $_cache_filename;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(_cache_active()) {
 | 
						if(_cache_active()) {
 | 
				
			||||||
		$data = gzcompress(ob_get_contents(), 9);
 | 
							$data = ob_get_contents();
 | 
				
			||||||
		if(CACHE_MEMCACHE) {
 | 
							if(CACHE_MEMCACHE) {
 | 
				
			||||||
			$_cache_memcache->set($_cache_hash, $data, 0, 600);
 | 
								$_cache_memcache->set($_cache_key, $data, 0, 600);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if(CACHE_DIR) {
 | 
							if(CACHE_DIR) {
 | 
				
			||||||
			file_put_contents($_cache_filename, $data);
 | 
								$zdata = gzcompress($data, 2);
 | 
				
			||||||
 | 
								file_put_contents($_cache_filename, $zdata);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user