@@ -63,7 +63,7 @@ public function __construct($prefix = '') {
63
63
\Memcached::OPT_LIBKETAMA_COMPATIBLE => true ,
64
64
65
65
// Enable Binary Protocol
66
- // \Memcached::OPT_BINARY_PROTOCOL => true,
66
+ \Memcached::OPT_BINARY_PROTOCOL => true ,
67
67
];
68
68
/**
69
69
* By default enable igbinary serializer if available
@@ -119,10 +119,7 @@ public function set($key, $value, $ttl = 0) {
119
119
} else {
120
120
$ result = self ::$ cache ->set ($ this ->getNameSpace () . $ key , $ value );
121
121
}
122
- if ($ result !== true ) {
123
- $ this ->verifyReturnCode ();
124
- }
125
- return $ result ;
122
+ return $ result || $ this ->isSuccess ();
126
123
}
127
124
128
125
public function hasKey ($ key ) {
@@ -132,10 +129,7 @@ public function hasKey($key) {
132
129
133
130
public function remove ($ key ) {
134
131
$ result = self ::$ cache ->delete ($ this ->getNameSpace () . $ key );
135
- if (self ::$ cache ->getResultCode () !== \Memcached::RES_NOTFOUND ) {
136
- $ this ->verifyReturnCode ();
137
- }
138
- return $ result ;
132
+ return $ result || $ this ->isSuccess () || self ::$ cache ->getResultCode () === \Memcached::RES_NOTFOUND ;
139
133
}
140
134
141
135
public function clear ($ prefix = '' ) {
@@ -151,14 +145,10 @@ public function clear($prefix = '') {
151
145
* @param mixed $value
152
146
* @param int $ttl Time To Live in seconds. Defaults to 60*60*24
153
147
* @return bool
154
- * @throws \Exception
155
148
*/
156
149
public function add ($ key , $ value , $ ttl = 0 ) {
157
150
$ result = self ::$ cache ->add ($ this ->getPrefix () . $ key , $ value , $ ttl );
158
- if (self ::$ cache ->getResultCode () !== \Memcached::RES_NOTSTORED ) {
159
- $ this ->verifyReturnCode ();
160
- }
161
- return $ result ;
151
+ return $ result || $ this ->isSuccess ();
162
152
}
163
153
164
154
/**
@@ -200,15 +190,7 @@ public static function isAvailable(): bool {
200
190
return extension_loaded ('memcached ' );
201
191
}
202
192
203
- /**
204
- * @throws \Exception
205
- */
206
- private function verifyReturnCode () {
207
- $ code = self ::$ cache ->getResultCode ();
208
- if ($ code === \Memcached::RES_SUCCESS ) {
209
- return ;
210
- }
211
- $ message = self ::$ cache ->getResultMessage ();
212
- throw new \Exception ("Error $ code interacting with memcached : $ message " );
193
+ private function isSuccess (): bool {
194
+ return self ::$ cache ->getResultCode () === \Memcached::RES_SUCCESS ;
213
195
}
214
196
}
0 commit comments