File cache sync via curl (#2851)

* Add sendevent when using file caching

* Create clear_cache.lua

FS receives a command via curl to call this script which deletes the single cache entry or flushes the entire cache.

* Create file_cache.lua

This scripts monitors for custom events. When an event is processed it will send out a command via curl to other FS servers telling them to clear their cache. 

This must be called from conf/autoload_configs/lua.conf.xml
 <param name="startup-script" value="app/server/resources/memcache.lua"/>
This commit is contained in:
konradSC
2017-09-20 18:19:56 -04:00
committed by FusionPBX
parent 2e321e4786
commit b969629f58
3 changed files with 157 additions and 7 deletions

View File

@@ -104,17 +104,34 @@ class cache {
//close event socket
fclose($fp);
}
//cache method file
if ($_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");
}
// 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::file\n";
$event .= "API-Command: cache\n";
$event .= "API-Command-Argument: delete ".$key."\n";
event_socket_request($fp, $event);
//remove the local files
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
@@ -147,16 +164,22 @@ class cache {
//close event socket
fclose($fp);
}
//cache method 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
$event = "sendevent CUSTOM\n";
$event .= "Event-Name: CUSTOM\n";
$event .= "Event-Subclass: fusion::file\n";
$event .= "API-Command: file\n";
$event .= "API-Command: cache\n";
$event .= "API-Command-Argument: flush\n";
event_socket_request($fp, $event);