@@ 329-361 (lines=33) @@ | ||
326 | * |
|
327 | * @return bool True on success, false on failure |
|
328 | */ |
|
329 | public function delete( $key, $time = 0 ) { |
|
330 | if ( !$this->_active ) { |
|
331 | return false; |
|
332 | } |
|
333 | ||
334 | $sock = $this->get_sock( $key ); |
|
335 | if ( !is_resource( $sock ) ) { |
|
336 | return false; |
|
337 | } |
|
338 | ||
339 | $key = is_array( $key ) ? $key[1] : $key; |
|
340 | ||
341 | if ( isset( $this->stats['delete'] ) ) { |
|
342 | $this->stats['delete']++; |
|
343 | } else { |
|
344 | $this->stats['delete'] = 1; |
|
345 | } |
|
346 | $cmd = "delete $key $time\r\n"; |
|
347 | if ( !$this->_fwrite( $sock, $cmd ) ) { |
|
348 | return false; |
|
349 | } |
|
350 | $res = $this->_fgets( $sock ); |
|
351 | ||
352 | if ( $this->_debug ) { |
|
353 | $this->_debugprint( sprintf( "MemCache: delete %s (%s)", $key, $res ) ); |
|
354 | } |
|
355 | ||
356 | if ( $res == "DELETED" || $res == "NOT_FOUND" ) { |
|
357 | return true; |
|
358 | } |
|
359 | ||
360 | return false; |
|
361 | } |
|
362 | ||
363 | /** |
|
364 | * Changes the TTL on a key from the server to $time |
|
@@ 371-403 (lines=33) @@ | ||
368 | * |
|
369 | * @return bool True on success, false on failure |
|
370 | */ |
|
371 | public function touch( $key, $time = 0 ) { |
|
372 | if ( !$this->_active ) { |
|
373 | return false; |
|
374 | } |
|
375 | ||
376 | $sock = $this->get_sock( $key ); |
|
377 | if ( !is_resource( $sock ) ) { |
|
378 | return false; |
|
379 | } |
|
380 | ||
381 | $key = is_array( $key ) ? $key[1] : $key; |
|
382 | ||
383 | if ( isset( $this->stats['touch'] ) ) { |
|
384 | $this->stats['touch']++; |
|
385 | } else { |
|
386 | $this->stats['touch'] = 1; |
|
387 | } |
|
388 | $cmd = "touch $key $time\r\n"; |
|
389 | if ( !$this->_fwrite( $sock, $cmd ) ) { |
|
390 | return false; |
|
391 | } |
|
392 | $res = $this->_fgets( $sock ); |
|
393 | ||
394 | if ( $this->_debug ) { |
|
395 | $this->_debugprint( sprintf( "MemCache: touch %s (%s)", $key, $res ) ); |
|
396 | } |
|
397 | ||
398 | if ( $res == "TOUCHED" ) { |
|
399 | return true; |
|
400 | } |
|
401 | ||
402 | return false; |
|
403 | } |
|
404 | ||
405 | /** |
|
406 | * @param string $key |