From a17b63e616fc86c73ec2efb5ad42672e5e0096e5 Mon Sep 17 00:00:00 2001 From: frytimo Date: Fri, 9 Feb 2024 13:21:55 -0400 Subject: [PATCH] Use the settings class in the cache class (#6891) --- resources/classes/cache.php | 76 ++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/resources/classes/cache.php b/resources/classes/cache.php index 7683c647f1..557d2cda63 100644 --- a/resources/classes/cache.php +++ b/resources/classes/cache.php @@ -1,20 +1,42 @@ settings = $settings; + $this->method = $this->setting('method'); + $this->syslog = $this->setting('syslog'); + $this->location = $this->setting('location'); + if (empty($this->method)) { + $this->method = 'file'; + } + if (empty($this->syslog)) { + $this->syslog = 'false'; + } + if (empty($this->location)) { + $this->location = '/var/cache/fusionpbx'; + } + } + + private function setting($subcategory) { + return $this->settings->get('cache', $subcategory); } /** @@ -28,7 +50,7 @@ class cache { $key = str_replace(":", ".", $key); //save to memcache - if ($_SESSION['cache']['method']['text'] == "memcache") { + if ($this->method === "memcache") { //connect to event socket $esl = event_socket::create(); if ($esl === false) { @@ -42,8 +64,8 @@ class cache { } //save to the file cache - if ($_SESSION['cache']['method']['text'] == "file") { - $result = file_put_contents($_SESSION['cache']['location']['text'] . "/" . $key, $value); + if ($this->method === "file") { + $result = file_put_contents($this->location . "/" . $key, $value); } //return result @@ -59,8 +81,8 @@ class cache { //change the delimiter $key = str_replace(":", ".", $key); - //cache method memcache - if ($_SESSION['cache']['method']['text'] == "memcache") { + //cache method memcache + if ($this->method === "memcache") { // connect to event socket $esl = event_socket::create(); if (!$esl->is_connected()) { @@ -76,9 +98,9 @@ class cache { } //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); + if ($this->method === "file") { + if (file_exists($this->location . "/" . $key)) { + $result = file_get_contents($this->location . "/" . $key); } } @@ -93,14 +115,14 @@ class cache { public function delete($key) { //debug information - if (isset($_SESSION['cache']['syslog']['boolean']) && $_SESSION['cache']['syslog']['boolean'] == "true") { + if ($this->syslog === "true") { openlog("fusionpbx", LOG_PID | LOG_PERROR, LOG_USER); syslog(LOG_WARNING, "debug: cache: [key: ".$key.", script: ".$_SERVER['SCRIPT_NAME'].", line: ".__line__."]"); closelog(); } - //cache method memcache - if (!empty($_SESSION['cache']['method']['text']) && $_SESSION['cache']['method']['text'] == "memcache") { + //cache method memcache + if ($this->method === "memcache") { //connect to event socket $esl = event_socket::create(); if ($esl === false) { @@ -122,7 +144,7 @@ class cache { } //cache method file - if (!empty($_SESSION['cache']['method']['text']) && $_SESSION['cache']['method']['text'] == "file") { + if ($this->method === "file") { //change the delimiter $key = str_replace(":", ".", $key); @@ -141,7 +163,7 @@ class cache { event_socket::command($event); //remove the local files - foreach (glob($_SESSION['cache']['location']['text'] . "/" . $key) as $file) { + foreach (glob($this->location . "/" . $key) as $file) { if (file_exists($file)) { unlink($file); } @@ -159,14 +181,14 @@ class cache { public function flush() { //debug information - if (isset($_SESSION['cache']['syslog']['boolean']) && $_SESSION['cache']['syslog']['boolean'] == "true") { + if ($this->syslog === "true") { openlog("fusionpbx", LOG_PID | LOG_PERROR, LOG_USER); syslog(LOG_WARNING, "debug: cache: [flush: all, script: ".$_SERVER['SCRIPT_NAME'].", line: ".__line__."]"); closelog(); } - //cache method memcache - if ($_SESSION['cache']['method']['text'] == "memcache") { + //cache method memcache + if ($this->method === "memcache") { // connect to event socket $esl = event_socket::create(); if ($esl === false) { @@ -187,8 +209,8 @@ class cache { } - //cache method file - if ($_SESSION['cache']['method']['text'] == "file") { + //cache method file + if ($this->method === "file") { // connect to event socket $esl = event_socket::create(); if ($esl === false) { @@ -204,7 +226,7 @@ class cache { event_socket::command($event); //remove the cache - recursive_delete($_SESSION['cache']['location']['text']); + recursive_delete($this->location); //set message $result = '+OK cache flushed';