PHP 8.5.0 Alpha 1 available for testing

Memcache::delete

memcache_delete

(PECL memcache >= 0.2.0)

Memcache::delete -- memcache_deleteElimina un elemento del servidor de caché

Descripción

Memcache::delete(string $key, int $exptime = 0): bool
memcache_delete(Memcache $memcache, string $key, int $exptime = 0): bool

Memcache::delete() elimina el elemento identificado por la clave key.

Parámetros

key

La clave asociada al elemento a eliminar.

exptime

Este argumento obsoleto no es soportado, y su valor por omisión es 0 segundos. No se debe utilizar este argumento.

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Historial de cambios

Versión Descripción
PECL memcache 3.0.5 El argumento exptime está deprecado y no debería ser proporcionado. Valores distintos de 0 pueden provocar errores inesperados.

Ejemplos

Ejemplo #1 Ejemplo con Memcache::delete()

<?php

/* API procedimental */
$memcache_obj = memcache_connect('memcache_host', 11211);

/* el elemento será eliminado por el servidor de caché */
memcache_delete($memcache_obj, 'key_to_delete');

/* API orientada a objetos */
$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host', 11211);

$memcache_obj->delete('key_to_delete');

?>

Ver también

add a note

User Contributed Notes 5 notes

up
6
nibblebot at gmail dot com
14 years ago
the Memcache::delete(key) function is broken on several combinations of memcached+pecl-memcache combinations.

pecl-memcache 2.2.5 + memcached 1.4.2 - Memcache::delete(key) WORKS

pecl-memcache 2.2.5 + memcached 1.4.3 - Memcache::delete(key) DOES NOT WORK

pecl-memcache 2.2.5 + memcached 1.4.4 - Memcache::delete(key) WORKS

pecl-memcache 2.2.5 + memcached 1.4.5 - Memcache::delete(key) WORKS

pecl-memcache 3.0.4 + memcached 1.4.2 - Memcache::delete(key) WORKS

pecl-memcache 3.0.4 + memcached 1.4.3 - Memcache::delete(key) DOES NOT WORK

pecl-memcache 3.0.4 + memcached 1.4.4 - Memcache::delete(key) DOES NOT WORK

pecl-memcache 3.0.4 + memcached 1.4.5 - Memcache::delete(key) DOES NOT WORK
up
3
vbaspcppguy at gmail dot com
14 years ago
According to the documents, $timeout is not required, but for me if I did not include it regardless of value, it fired an error. I made a simple fix for it.

<?php
class memcache_tools extends memcache
{
public function
delete($key, $expire=0)
{
parent::delete($key, $expire);
}
}
?>

This will force it to behave as it should regardless of version.
up
0
me at adamhahn dot com
13 years ago
I could not get the delete to work properly, so I ended up trying the 'set' method and setting the timeout value to -1.

<?php
$memcache
->set('index', 'deleted', 0, -1);
?>

It solved my problem with the delete method.

(using memcached 1.4.5 and pecl-memcache 3.0.6)
up
-1
padys
12 years ago
In my case this code does NOT work:
<?php
$memcache
->set('index', 'deleted', 0, -1);
?>
because of expire == -1.

I set expire = 1 (and I prefer "replace"):
<?php
$memcache
->replace('index', '', 0, 1);
?>
up
-4
Anonymous
14 years ago
Regardless of whether or not it succeeds, for me on Ubuntu 10.04 it always returns false. Just an FYI, you can't seem to rely on the result.
To Top