1: <?php
2: 3: 4: 5: 6: 7:
8:
9: namespace GLFramework\Cache;
10:
11:
12: class MemcachedCache extends Cache
13: {
14:
15: 16: 17:
18: private $conn;
19: private $connected = false;
20: public function set($key, $value, $duration = null)
21: {
22:
23: if($this->connected)
24: {
25: return $this->conn->set($key, $value, null, $duration);
26: }
27: }
28:
29: public function get($key)
30: {
31:
32: if($this->connected)
33: {
34: return $this->conn->get($key);
35: }
36: }
37:
38: public function hash($key)
39: {
40:
41: if($this->connected)
42: {
43: return $this->get($key) != null;
44: }
45: return false;
46: }
47:
48: public function remove($key)
49: {
50:
51: if($this->connected)
52: {
53: return $this->conn->delete($key);
54: }
55: }
56:
57: public function connect($config = array())
58: {
59:
60: if(isset($config['database']['cache']))
61: {
62: $configCache = $config['database']['cache'];
63: $this->conn = new \Memcache();
64: if($this->conn->connect($configCache['host'], $configCache['port'], $configCache['timeout']))
65: {
66: $this->connected = true;
67: return true;
68: }
69: }
70: return false;
71: }
72: }