1 | <?php |
||
12 | class MemcacheStorage extends AbstractStorage implements StorageInterface { |
||
13 | |||
14 | /** |
||
15 | * Server ip |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $server; |
||
19 | |||
20 | /** |
||
21 | * Port number |
||
22 | * @var int |
||
23 | */ |
||
24 | protected $port; |
||
25 | |||
26 | /** |
||
27 | * Info method |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $infoMethod = 'getStats'; |
||
31 | |||
32 | /** |
||
33 | * Constructor |
||
34 | * |
||
35 | * @param array $options |
||
36 | */ |
||
37 | public function __construct($memcache, array $options = array()) { |
||
43 | |||
44 | /** |
||
45 | * Initialise Cache storage |
||
46 | * |
||
47 | * @return bool |
||
48 | * |
||
49 | * @throws \Kemist\Cache\Exception |
||
50 | */ |
||
51 | public function init() { |
||
54 | |||
55 | /** |
||
56 | * Checks if the specified name in cache exists |
||
57 | * |
||
58 | * @param string $name cache name |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function has($name) { |
||
63 | if ($this->provider->get($this->prefix . $name)) { |
||
64 | return true; |
||
65 | } |
||
66 | return false; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Saves the variable to the $name cache |
||
71 | * |
||
72 | * @param string $name cache name |
||
73 | * @param mixed $val variable to be stored |
||
74 | * @param bool $compressed |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function store($name, $val, $compressed = false) { |
||
79 | $realName = $this->prefix . $name; |
||
80 | $success = true; |
||
81 | if ($compressed && $this->provider->replace($realName, $val, 2) == false) { |
||
82 | $success = $this->provider->set($realName, $val, 2); |
||
83 | } elseif ($this->provider->replace($realName, $val) == false) { |
||
84 | $success = $this->provider->set($realName, $val); |
||
85 | } |
||
86 | $success ? $this->storeName($name) : null; |
||
87 | return $success; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Destructor |
||
92 | * |
||
93 | * @return type |
||
94 | */ |
||
95 | public function __destruct() { |
||
98 | |||
99 | } |
||
100 |