Skip to content

Commit 20352de

Browse files
committed
Update caching.class.php
Clearing the cache fix
1 parent f17966e commit 20352de

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

lib/caching.class.php

+26-33
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,47 @@
44
* @param mixed $prefix prefix
55
* @return void
66
*/
7-
function clearCacheData($prefix='') {
8-
$prefix=strtolower($prefix);
9-
/*
10-
$apcu_available = function_exists('apcu_enabled') && apcu_enabled();
11-
if ($apcu_available) {
12-
apcu_clear_cache();
13-
}
14-
*/
7+
function clearCacheData($prefix = '')
8+
{
9+
$prefix = strtolower($prefix);
1510
if (defined('USE_REDIS')) {
1611
global $redisConnection;
1712
if (!isset($redisConnection)) {
1813
$redisConnection = new Redis();
1914
$redisConnection->pconnect(USE_REDIS);
2015
}
21-
if(!prefix)$redisConnection->flushDB();
22-
else
23-
{
24-
$list=$redisConnection->getKeys($prefix."*");
25-
foreach($list as $key1)
26-
$redisConnection->del($key1);
27-
}
16+
if (!$prefix) $redisConnection->flushDB();
17+
else {
18+
$list = $redisConnection->getKeys($prefix . "*");
19+
foreach ($list as $key1)
20+
$redisConnection->del($key1);
21+
}
2822
return;
2923
}
30-
if(!$prefix)SQLTruncateTable('cached_values');
31-
else SQLExec("delete from cached_values where KEYWORD like '$prefix%'");
24+
if (!$prefix) SQLTruncateTable('cached_values');
25+
else SQLExec("delete from cached_values where KEYWORD like '$prefix%'");
3226
}
3327

3428
/**
3529
* Return all Cache Data from prefix
3630
* Summary of getAllCache
37-
* @param mixed $prefix
31+
* @param mixed $prefix
3832
* @return array
3933
*/
40-
function getAllCache($prefix='')
34+
function getAllCache($prefix = '')
4135
{
42-
$prefix=strtolower($prefix);
43-
$out=array();
36+
$prefix = strtolower($prefix);
37+
$out = array();
4438
if (defined('USE_REDIS')) {
4539
global $redisConnection;
4640
if (!isset($redisConnection)) {
4741
$redisConnection = new Redis();
4842
$redisConnection->pconnect(USE_REDIS);
4943
}
50-
$list=$redisConnection->getKeys($prefix."*");
51-
foreach($list as $key1)
52-
$out[$key1]=$redisConnection->get($key1);
53-
}
54-
else $out=SQLExec("select * from cached_values where KEYWORD like '$prefix%'");
44+
$list = $redisConnection->getKeys($prefix . "*");
45+
foreach ($list as $key1)
46+
$out[$key1] = $redisConnection->get($key1);
47+
} else $out = SQLExec("select * from cached_values where KEYWORD like '$prefix%'");
5548
return $out;
5649
}
5750

@@ -64,9 +57,9 @@ function getAllCache($prefix='')
6457
*/
6558
function saveToCache($key, $value)
6659
{
67-
$key=strtolower($key);
60+
$key = strtolower($key);
6861
if (is_array($value) || strlen($value) > 255) {
69-
SQLExec("DELETE FROM cached_values WHERE KEYWORD='" . $key . "'");
62+
SQLExec("DELETE FROM cached_values WHERE KEYWORD='" . $key . "'");
7063
return;
7164
}
7265

@@ -80,7 +73,7 @@ function saveToCache($key, $value)
8073
return;
8174
}
8275

83-
$rec = array('KEYWORD' => $key, 'DATAVALUE' => $value);
76+
$rec = array('KEYWORD' => $key, 'DATAVALUE' => $value);
8477
$sqlQuery = "REPLACE INTO cached_values (KEYWORD, DATAVALUE) " .
8578
" VALUES ('" . DbSafe1($rec['KEYWORD']) . "', " .
8679
"'" . DbSafe1($rec['DATAVALUE']) . "')";
@@ -94,7 +87,7 @@ function saveToCache($key, $value)
9487
*/
9588
function checkFromCache($key)
9689
{
97-
$key=strtolower($key);
90+
$key = strtolower($key);
9891
if (defined('USE_REDIS')) {
9992
global $redisConnection;
10093
if (!isset($redisConnection)) {
@@ -110,7 +103,7 @@ function checkFromCache($key)
110103
}
111104

112105

113-
$rec = SQLSelectOne("SELECT * FROM cached_values WHERE KEYWORD = '" . DBSafe($key) . "'");
106+
$rec = SQLSelectOne("SELECT * FROM cached_values WHERE KEYWORD = '" . DBSafe($key) . "'");
114107

115108
if (isset($rec['KEYWORD'])) {
116109
return $rec['DATAVALUE'];
@@ -177,7 +170,7 @@ function postToWebSocket($property, $value, $post_action = 'PostProperty')
177170
}
178171
}
179172

180-
if (!Is_Object($wsClient) && IsSet($_SERVER['REQUEST_METHOD'])) {
173+
if (!Is_Object($wsClient) && isset($_SERVER['REQUEST_METHOD'])) {
181174
return false;
182175
}
183176

@@ -208,7 +201,7 @@ function postToWebSocket($property, $value, $post_action = 'PostProperty')
208201
}
209202
}
210203

211-
if (!$data_sent && !IsSet($_SERVER['REQUEST_METHOD'])) {
204+
if (!$data_sent && !isset($_SERVER['REQUEST_METHOD'])) {
212205
//reconnect
213206
$wsClient = new WebsocketClient;
214207
if ((@$wsClient->connect('127.0.0.1', WEBSOCKETS_PORT, '/majordomo'))) {

0 commit comments

Comments
 (0)