Or just set the value within the callback with your own custom expiration time and return false. I think it's cleaner.
Las funciones de retorno para claves ausentes son invocadas cuando un elemento no puede
ser leído en el servidor. La función de retorno recibe un objeto Memcached,
la clave solicitada, y un valor de variable por referencia. La función de retorno
es entonces responsable de asignar el valor, y luego devolver
true
o false
. Si la función de retorno devuelve true
Memcached almacenará el valor así creado en el servidor, y lo devolverá
a la función invocante. Solo Memcached::get() y
Memcached::getByKey() soportan estas funciones,
ya que el protocolo memcache no proporciona ninguna información sobre la ausencia de
clave en una petición multiclave.
Ejemplo #1 Funciones de retorno para claves ausentes
<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
$profile_info = $m->get('user:'.$user_id, 'user_info_cb');
function user_info_cb($memc, $key, &$value)
{
$user_id = substr($key, 5);
/* Lee un perfil en una base de datos */
/* ... */
$value = $profile_info;
return true;
}
?>
Or just set the value within the callback with your own custom expiration time and return false. I think it's cleaner.
This isn't specified anywhere, so I had a gander at the source...
The expiry on read-through cache set values is set to 0, or forever. This means if you want your key to implicitly expire, don't use the callback methods, instead check for boolean false as a return and manually set the value, at least for now.