3 namespace Friendica\Core\Cache;
\r
5 use Friendica\BaseObject;
\r
6 use Friendica\Core\Cache;
\r
9 * Memcached Cache Driver
\r
11 * @author Hypolite Petovan <mrpetovan@gmail.com>
\r
13 class MemcachedCacheDriver extends BaseObject implements ICacheDriver
\r
20 public function __construct(array $memcached_hosts)
\r
22 if (!class_exists('Memcached', false)) {
\r
23 throw new \Exception('Memcached class isn\'t available');
\r
26 $this->memcached = new \Memcached();
\r
28 $this->memcached->addServers($memcached_hosts);
\r
30 if (count($this->memcached->getServerList()) == 0) {
\r
31 throw new \Exception('Expected Memcached servers aren\'t available, config:' . var_export($memcached_hosts, true));
\r
35 public function get($key)
\r
39 // We fetch with the hostname as key to avoid problems with other applications
\r
40 $value = $this->memcached->get(self::getApp()->get_hostname() . ':' . $key);
\r
42 if ($this->memcached->getResultCode() === \Memcached::RES_SUCCESS) {
\r
49 public function set($key, $value, $duration = Cache::MONTH)
\r
51 // We store with the hostname as key to avoid problems with other applications
\r
52 return $this->memcached->set(
\r
53 self::getApp()->get_hostname() . ":" . $key,
\r
55 Cache::duration($duration)
\r
59 public function delete($key)
\r
61 return $this->memcached->delete($key);
\r
64 public function clear()
\r