1 | <?php |
||
20 | class MemcacheStorage extends AbstractStorage |
||
21 | { |
||
22 | /** |
||
23 | * @var \Memcached |
||
24 | */ |
||
25 | private $mmc; |
||
26 | |||
27 | /** |
||
28 | * MemcacheStorage constructor. |
||
29 | * @param \Memcached $memcache |
||
30 | * @param string $server |
||
31 | * @param int $port |
||
32 | * @param DateInterval $ttl |
||
33 | */ |
||
34 | 7 | public function __construct(\Memcached $memcache, $server = 'localhost', $port = 11211, DateInterval $ttl) |
|
40 | |||
41 | /** |
||
42 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
||
43 | * |
||
44 | * @param string $key The key of the item to store. |
||
45 | * @param mixed $value The value of the item to store, must be serializable. |
||
46 | * @param null|int $ttl Optional. The TTL value of this item. If no value is sent and |
||
47 | * the driver supports TTL then the library may set a default value |
||
48 | * for it or let the driver take care of that. |
||
49 | * |
||
50 | * @return bool True on success and false on failure. |
||
51 | */ |
||
52 | 1 | public function set($key, $value, $ttl = null) |
|
57 | |||
58 | /** |
||
59 | * Determines whether an item is present in the cache. |
||
60 | * |
||
61 | * NOTE: It is recommended that has() is only to be used for cache warming type purposes |
||
62 | * and not to be used within your live applications operations for get/set, as this method |
||
63 | * is subject to a race condition where your has() will return true and immediately after, |
||
64 | * another script can remove it making the state of your app out of date. |
||
65 | * |
||
66 | * @param string $key The cache item key. |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | 2 | public function has($key){ |
|
76 | |||
77 | /** |
||
78 | * Fetches a value from the cache. |
||
79 | * |
||
80 | * @param string $key The unique key of this item in the cache. |
||
81 | * |
||
82 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
||
83 | * |
||
84 | */ |
||
85 | 1 | public function get($key) |
|
89 | |||
90 | /** |
||
91 | * Delete an item from the cache by its unique key. |
||
92 | * |
||
93 | * @param string $key The unique cache key of the item to delete. |
||
94 | * |
||
95 | * @return bool True if the item was successfully removed. False if there was an error. |
||
96 | */ |
||
97 | 1 | public function delete($key) |
|
101 | |||
102 | /** |
||
103 | * @param int $delay |
||
104 | * @return bool |
||
105 | */ |
||
106 | 1 | public function flush($delay = 0) |
|
110 | |||
111 | /** |
||
112 | * Wipes clean the entire cache's keys. |
||
113 | * |
||
114 | * @return bool True on success and false on failure. |
||
115 | */ |
||
116 | public function clear(){ |
||
117 | return $this->flush(); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Add new server to Memcache pool. |
||
122 | * @param $server |
||
123 | * @param $port |
||
124 | */ |
||
125 | 1 | public function addServer($server, $port) |
|
129 | } |
||
130 |