Or just set the value within the callback with your own custom expiration time and return false. I think it's cleaner.
Lectura de caché de llamadas de retorno
La lectura de caché de llamadas de retorno se invoca cuando un ítem no puede ser obtenido de un servidor. La llamada de retorno es pasada al objecto Memcached junto con la petición de la clave y el valor de la variable por referencia. La llamada de retorno se encarga de definir el valor y devolver true o false. Si la llamada de retorno devuelve true, Memcached guardará el valor en el servidor y lo devolverá en la llamada de la función original Memcached::get() y Memcached::getByKey() soportan llamadas de retorno, ya que el protocolo memcache no provee información sobre las claves que no fueron encontradas en una petición múltiple.
Ejemplo #1 Ejemplo de lectura de llamada de retorno
<?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);
/* busca el profile en la BD */
/* ... */
$value = $profile_info;
return true;
}
?>
chadkouse ¶
1 year ago
oorza2k5 at gmail dot com ¶
4 years ago
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.
chadkouse ¶
1 year ago
the expiration time set for you if you return true from the callback will be 0 (forever) - so if you want a different expiration time you can do the SET operation inside the callback with your custom expiration time. just make sure you return FALSE from the callback to prevent the client from automatically setting the value again.
