Hauk/backend/include/wrapper/memcached.php
2019-08-24 22:59:03 +02:00

36 lines
1 KiB
PHP

<?php
// This class is a wrapper class for the `memcached` extension in PHP. Hauk
// maintains compatibility with both `memcache` and `memcached`, and therefore
// needs an abstraction layer between itself and the extensions to ensure a
// unified interface for both.
class MemWrapper {
private $memcache = null;
function __construct($host, $port) {
$this->memcache = new Memcached();
$this->memcache->addServer(CONFIG["memcached_host"], CONFIG["memcached_port"])
or die ("Server could not connect to memcached!\n");
}
function get($key) {
$data = $this->memcache->get($key);
if ($data === false) return false;
return json_decode($data, true);
}
function set($key, $data, $duration) {
$this->memcache->set($key, json_encode($data), time() + $duration);
}
function replace($key, $data) {
$this->memcache->replace($key, json_encode($data));
}
function delete($key) {
$this->memcache->delete($key);
}
}
?>