Browse Source

Update cache.php

FusionPBX 8 năm trước cách đây
mục cha
commit
7e302d7f61
1 tập tin đã thay đổi với 68 bổ sung34 xóa
  1. 68 34
      resources/classes/cache.php

+ 68 - 34
resources/classes/cache.php

@@ -81,26 +81,41 @@ class cache {
 	 * @var string $key		cache id
 	 */
 	public function delete($key) {
-		// connect to event socket
-			$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
-			if ($fp === false) {
-				return false;
-			}
-
-		//send a custom event
-			$event = "sendevent CUSTOM\n";
-			$event .= "Event-Name: CUSTOM\n";
-			$event .= "Event-Subclass: fusion::memcache\n";
-			$event .= "API-Command: memcache\n";
-			$event .= "API-Command-Argument: delete ".$key."\n";
-			event_socket_request($fp, $event);
 
-		//run the memcache
-			$command = "memcache delete ".$key;
-			$result = event_socket_request($fp, 'api '.$command);
+		//cache method memcache 
+			if (strlen($_SESSION['cache']['method']['text']) == "memcache") {
+				// connect to event socket
+					$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
+					if ($fp === false) {
+						return false;
+					}
+
+				//send a custom event
+					$event = "sendevent CUSTOM\n";
+					$event .= "Event-Name: CUSTOM\n";
+					$event .= "Event-Subclass: fusion::memcache\n";
+					$event .= "API-Command: memcache\n";
+					$event .= "API-Command-Argument: delete ".$key."\n";
+					event_socket_request($fp, $event);
+
+				//run the memcache
+					$command = "memcache delete ".$key;
+					$result = event_socket_request($fp, 'api '.$command);
+
+				//close event socket
+					fclose($fp);
+			}
 
-		//close event socket
-			fclose($fp);
+		//cache method file 
+			if (strlen($_SESSION['cache']['method']['text']) == "file") {
+				$key = str_replace(":", ".", $key);
+				if (file_exists($_SESSION['cache']['location']['text'] . "/" . $key)) {
+					unlink($_SESSION['cache']['location']['text'] . "/" . $key);
+					if (file_exists($_SESSION['cache']['location']['text'] . "/" . $key . ".tmp")) {
+						unlink($_SESSION['cache']['location']['text'] . "/" . $key . ".tmp");
+					}
+				}
+			}
 
 		// return result
 			return $result;
@@ -110,26 +125,45 @@ class cache {
 	 * Delete the entire cache
 	 */
 	public function flush() {
-		// connect to event socket
-			$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
-			if ($fp === false) {
-				return false;
+		//cache method memcache 
+			if (strlen($_SESSION['cache']['method']['text']) == "memcache") {
+				// connect to event socket
+					$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
+					if ($fp === false) {
+						return false;
+					}
+		
+				//send a custom event
+					$event = "sendevent CUSTOM\n";
+					$event .= "Event-Name: CUSTOM\n";
+					$event .= "Event-Subclass: fusion::memcache\n";
+					$event .= "API-Command: memcache\n";
+					$event .= "API-Command-Argument: flush\n";
+					event_socket_request($fp, $event);
+		
+				//run the memcache
+					$command = "memcache flush";
+					$result = event_socket_request($fp, 'api '.$command);
+		
+				//close event socket
+					fclose($fp);
 			}
 
-		//send a custom event
-			$event = "sendevent CUSTOM\n";
-			$event .= "Event-Name: CUSTOM\n";
-			$event .= "Event-Subclass: fusion::memcache\n";
-			$event .= "API-Command: memcache\n";
-			$event .= "API-Command-Argument: flush\n";
-			event_socket_request($fp, $event);
+		//cache method file 
+			if (strlen($_SESSION['cache']['method']['text']) == "file") {
 
-		//run the memcache
-			$command = "memcache flush";
-			$result = event_socket_request($fp, 'api '.$command);
+				//send a custom event
+					$event = "sendevent CUSTOM\n";
+					$event .= "Event-Name: CUSTOM\n";
+					$event .= "Event-Subclass: fusion::file\n";
+					$event .= "API-Command: file\n";
+					$event .= "API-Command-Argument: flush\n";
+					event_socket_request($fp, $event);
 
-		//close event socket
-			fclose($fp);
+				//remove the cache
+					recursive_delete($_SESSION['cache']['location']['text']);
+
+			}
 
 		// return result
 			return $result;