From 7e0e6785787fe991fb197bdf5e8a5f3b8dfb492b Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Thu, 15 Jan 2015 18:15:25 +0000 Subject: [PATCH] Add the first version of the cache class. --- resources/classes/cache.php | 104 ++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 resources/classes/cache.php diff --git a/resources/classes/cache.php b/resources/classes/cache.php new file mode 100644 index 0000000000..f01b1376ee --- /dev/null +++ b/resources/classes/cache.php @@ -0,0 +1,104 @@ + $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; + } + } + +?> \ No newline at end of file