CakeFest 2024: The Official CakePHP Conference

Tiempos de expiración

Algunos comandos de almacenamiento implican el envío de un valor de expiración (relativo a un ítem o a una operación solicitada por el cliente) al servidor. En todos los casos, el valor real enviado podría ser en tiempo Unix (un valor de tipo integer con el número de segundos transcurridos desde el 1 de enero de 1970), o el número de segundos comenzando desde el instante actual. En este caso, el número no debe exceder de 60*60*24*30 (que corresponde al número de segundos en 30 días); si se excede el valor del tiempo de expiración, el servidor lo considerará como tiempo Unix en lugar del número de segundos desde el instante actual.

Si el valor de la expiración es 0 (el predeterminado), el ítem nunca caducará (aunque puede ser eliminado del servidor para hacer sitio a otros ítems).

add a note

User Contributed Notes 2 notes

up
5
valugi at gmail dot com
7 years ago
The fact that one sets an expiration time does not mean that the keys will expire at that particular time. I'm not sure what is happening in the background, if there is a process like a garbage collector that expire keys, but some function do not activate the expiration check and return the key as valid, for example `getAllKeys` is not atomic and returns even expired keys.

$memcached = new Memcached();
$memcached->set('key','value',10);
//waiting more than 10 sec
sleep(20);
$data = $memcached->getAllKeys();
var_dump($data); // key will still be listed
$key = $memcached->get('key'); // will trigger the expiration
up
-1
i dot caught dot air at gmail dot com
6 years ago
A TTL of n seconds will expire between n and n-1 seconds as memcache doesn't use a high-resolution clock internally.

This is important to consider if you're working with very short TTLs.

See https://github.com/memcached/memcached/issues/307
To Top