Update cache.php

This commit is contained in:
FusionPBX
2019-07-30 00:11:50 -06:00
committed by GitHub
parent e4257ab752
commit 6202f6ab79
+22 -6
View File
@@ -33,6 +33,8 @@ class cache {
* @var string $value string to be cached * @var string $value string to be cached
*/ */
public function set($key, $value) { public function set($key, $value) {
//save to memcache
if ($_SESSION['cache']['method']['text'] == "memcache") {
//connect to event socket //connect to event socket
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp === false) { if ($fp === false) {
@@ -47,6 +49,14 @@ class cache {
//close event socket //close event socket
fclose($fp); fclose($fp);
}
//save to the file cache
if ($_SESSION['cache']['method']['text'] == "file") {
if (file_exists($_SESSION['cache']['location']['text'] . "/" . $key)) {
$result = file_put_contents($_SESSION['cache']['location']['text'] . "/" . $key, $value);
}
}
// return result // return result
return $result; return $result;
@@ -57,6 +67,9 @@ class cache {
* @var string $key cache id * @var string $key cache id
*/ */
public function get($key) { public function get($key) {
//cache method memcache
if ($_SESSION['cache']['method']['text'] == "memcache") {
// connect to event socket // connect to event socket
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp === false) { if ($fp === false) {
@@ -72,6 +85,15 @@ class cache {
//close event socket //close event socket
fclose($fp); fclose($fp);
}
//get the file cache
if ($_SESSION['cache']['method']['text'] == "file") {
if (file_exists($_SESSION['cache']['location']['text'] . "/" . $key)) {
$result = file_get_contents($_SESSION['cache']['location']['text'] . "/" . $key);
}
}
// return result // return result
return $result; return $result;
} }
@@ -170,12 +192,6 @@ class cache {
//cache method file //cache method file
if ($_SESSION['cache']['method']['text'] == "file") { if ($_SESSION['cache']['method']['text'] == "file") {
// 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 //send a custom event
$event = "sendevent CUSTOM\n"; $event = "sendevent CUSTOM\n";
$event .= "Event-Name: CUSTOM\n"; $event .= "Event-Name: CUSTOM\n";