mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-23 22:52:12 +01:00
121 lines
3.2 KiB
XML
121 lines
3.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 80872147aa52367137bd3d168412f70cbe2ddf9c Maintainer: marcosmarcolin Status: ready --><!-- CREDITS: marcosmarcolin -->
|
|
|
|
<chapter xml:id="memcached.callbacks" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<title>Funções de Retorno</title>
|
|
|
|
<section xml:id="memcached.callbacks.result">
|
|
<title>Funções de retorno de resultados</title>
|
|
<para>
|
|
<type>callable</type>s de resultados são chamados pelos métodos
|
|
<methodname>Memcached::getDelayed</methodname> ou
|
|
<methodname>Memcached::getDelayedBykey</methodname> para cada item no conjunto de
|
|
resultados. A função de retorno recebe o objeto Memcached e o array
|
|
com as informações do item. A função não precisa retornar nada.
|
|
</para>
|
|
<example>
|
|
<title>Exemplo de função de retorno de resultado</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$m = new Memcached();
|
|
$m->addServer('localhost', 11211);
|
|
$items = array(
|
|
'key1' => 'value1',
|
|
'key2' => 'value2',
|
|
'key3' => 'value3'
|
|
);
|
|
$m->setMulti($items);
|
|
$m->getDelayed(array('key1', 'key3'), true, 'result_cb');
|
|
|
|
function result_cb($memc, $item)
|
|
{
|
|
var_dump($item);
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
array(3) {
|
|
["key"]=>
|
|
string(4) "key1"
|
|
["value"]=>
|
|
string(6) "value1"
|
|
["cas"]=>
|
|
float(49)
|
|
}
|
|
array(3) {
|
|
["key"]=>
|
|
string(4) "key3"
|
|
["value"]=>
|
|
string(6) "value3"
|
|
["cas"]=>
|
|
float(50)
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</section>
|
|
|
|
<section xml:id="memcached.callbacks.read-through">
|
|
<title>Funções de retorno de cache de leitura</title>
|
|
<para>
|
|
As funções de retorno do cache de leitura são invocadas quando um item não pode ser
|
|
recuperado do servidor. A função recebe o objeto Memcached, a chave solicitada
|
|
e a variável de valor por referência. A função é responsável por definir o valor e
|
|
retornar true ou false. Se a função retornar true,
|
|
o Memcached armazenará o valor preenchido no servidor e o retornará à
|
|
função de chamada original. Somente <methodname>Memcached::get</methodname> e
|
|
<methodname>Memcached::getByKey</methodname> suportam essas funções de retorno,
|
|
porque o protocolo memcache não fornece informações sobre quais chaves não foram
|
|
encontradas na requisição de multi-chaves.
|
|
</para>
|
|
<example>
|
|
<title>Exemplo de função de retorno de leitura</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?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);
|
|
/* pesquisa o perfil no banco de dados */
|
|
/* ... */
|
|
$value = $profile_info;
|
|
return true;
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</section>
|
|
|
|
</chapter>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|