Update cache.php
This commit is contained in:
+46
-30
@@ -33,20 +33,30 @@ 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) {
|
||||||
// connect to event socket
|
//save to memcache
|
||||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
if ($_SESSION['cache']['method']['text'] == "memcache") {
|
||||||
if ($fp === false) {
|
//connect to event socket
|
||||||
return false;
|
$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
|
||||||
|
|
||||||
|
//run the memcache
|
||||||
|
$command = "memcache set ".$key." ".$value;
|
||||||
|
$result = event_socket_request($fp, 'api '.$command);
|
||||||
|
|
||||||
|
//close event socket
|
||||||
|
fclose($fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
//send a custom event
|
//save to the file cache
|
||||||
|
if ($_SESSION['cache']['method']['text'] == "file") {
|
||||||
//run the memcache
|
if (file_exists($_SESSION['cache']['location']['text'] . "/" . $key)) {
|
||||||
$command = "memcache set ".$key." ".$value;
|
$result = file_put_contents($_SESSION['cache']['location']['text'] . "/" . $key, $value);
|
||||||
$result = event_socket_request($fp, 'api '.$command);
|
}
|
||||||
|
}
|
||||||
//close event socket
|
|
||||||
fclose($fp);
|
|
||||||
|
|
||||||
// return result
|
// return result
|
||||||
return $result;
|
return $result;
|
||||||
@@ -57,20 +67,32 @@ class cache {
|
|||||||
* @var string $key cache id
|
* @var string $key cache id
|
||||||
*/
|
*/
|
||||||
public function get($key) {
|
public function get($key) {
|
||||||
// connect to event socket
|
|
||||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
//cache method memcache
|
||||||
if ($fp === false) {
|
if ($_SESSION['cache']['method']['text'] == "memcache") {
|
||||||
return false;
|
// 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
|
||||||
|
|
||||||
|
//run the memcache
|
||||||
|
$command = "memcache get ".$key;
|
||||||
|
$result = event_socket_request($fp, 'api '.$command);
|
||||||
|
|
||||||
|
//close event socket
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//send a custom event
|
//get the file cache
|
||||||
|
if ($_SESSION['cache']['method']['text'] == "file") {
|
||||||
//run the memcache
|
if (file_exists($_SESSION['cache']['location']['text'] . "/" . $key)) {
|
||||||
$command = "memcache get ".$key;
|
$result = file_get_contents($_SESSION['cache']['location']['text'] . "/" . $key);
|
||||||
$result = event_socket_request($fp, 'api '.$command);
|
}
|
||||||
|
}
|
||||||
//close event socket
|
|
||||||
fclose($fp);
|
|
||||||
|
|
||||||
// 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";
|
||||||
|
|||||||
Reference in New Issue
Block a user