mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Add the first version of the cache class.
This commit is contained in:
104
resources/classes/cache.php
Normal file
104
resources/classes/cache.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* cache class provides an abstracted cache
|
||||
*
|
||||
* @method string send
|
||||
*/
|
||||
class cache {
|
||||
|
||||
/**
|
||||
* @var string $type type of cache current options memcache
|
||||
*/
|
||||
private $zzz;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//place holder
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a specific item in the cache
|
||||
* @var string $key the cache id
|
||||
* @var string $value string to be cached
|
||||
*/
|
||||
private function set($key, $value) {
|
||||
//send a custom event
|
||||
|
||||
//run the memcache
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp) {
|
||||
$command = "memcache set ".$key." ".$value;
|
||||
$return = event_socket_request($fp, 'api '.$command);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific item from the cache
|
||||
* @var string $key cache id
|
||||
*/
|
||||
private function get($key) {
|
||||
//send a custom event
|
||||
|
||||
//run the memcache
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp) {
|
||||
$command = "memcache get ".$key;
|
||||
$return = event_socket_request($fp, 'api '.$command);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific item from the cache
|
||||
* @var string $key cache id
|
||||
*/
|
||||
private function delete($key) {
|
||||
//send a custom event
|
||||
|
||||
//run the memcache
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp) {
|
||||
$command = "memcache delete ".$key;
|
||||
$return = event_socket_request($fp, 'api '.$command);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the entire cache
|
||||
*/
|
||||
private function flush() {
|
||||
//send a custom event
|
||||
|
||||
//run the memcache
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp) {
|
||||
$command = "memcache flush";
|
||||
$return = event_socket_request($fp, 'api '.$command);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user