Hauk/backend/include/wrapper/memcached.php
Marius Lindvall 4977b31507 Add support for group shares; fixes #7
See #7 for more details
2019-09-09 14:32:12 +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, $expire) {
$this->memcache->set($key, json_encode($data), $expire);
}
function replace($key, $data) {
$this->memcache->replace($key, json_encode($data), $expire);
}
function delete($key) {
$this->memcache->delete($key);
}
}
?>