<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/memcached.callbacks.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'tr',
  ),
  'this' => 
  array (
    0 => 'memcached.callbacks.read-through.php',
    1 => 'Read-through cache callbacks',
    2 => 'Read-through cache callbacks',
  ),
  'up' => 
  array (
    0 => 'memcached.callbacks.php',
    1 => 'Callbacks',
  ),
  'prev' => 
  array (
    0 => 'memcached.callbacks.result.php',
    1 => 'Result callbacks',
  ),
  'next' => 
  array (
    0 => 'memcached.sessions.php',
    1 => 'Sessions support',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/memcached/callbacks.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="memcached.callbacks.read-through" class="section">
  <h2 class="title">Read-through cache callbacks</h2>
  <p class="para">
   Read-through cache callbacks are invoked when an item cannot be retrieved
   from the server. The callback is passed the Memcached object, the requested
   key, and the by-reference value variable. The callback is responsible for
   setting the value and returning true or false. If the callback returns true,
   Memcached will store the populated value on the server and return it to the
   original calling function. Only <span class="methodname"><a href="memcached.get.php" class="methodname">Memcached::get()</a></span> and
   <span class="methodname"><a href="memcached.getbykey.php" class="methodname">Memcached::getByKey()</a></span> support these callbacks,
   because the memcache protocol does not provide information on which keys
   were not found in the multi-key request.
  </p>
  <div class="example" id="example-1">
   <p><strong>Örnek 1 Read-through callback example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$m </span><span style="color: #007700">= new </span><span style="color: #0000BB">Memcached</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$profile_info </span><span style="color: #007700">= </span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'user:'</span><span style="color: #007700">.</span><span style="color: #0000BB">$user_id</span><span style="color: #007700">, </span><span style="color: #DD0000">'user_info_cb'</span><span style="color: #007700">);<br /><br />function </span><span style="color: #0000BB">user_info_cb</span><span style="color: #007700">(</span><span style="color: #0000BB">$memc</span><span style="color: #007700">, </span><span style="color: #0000BB">$key</span><span style="color: #007700">, &amp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)<br />{<br />    </span><span style="color: #0000BB">$user_id </span><span style="color: #007700">= </span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$key</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">);<br />    </span><span style="color: #FF8000">/* lookup profile info in the DB */<br />    /* ... */<br />    </span><span style="color: #0000BB">$value </span><span style="color: #007700">= </span><span style="color: #0000BB">$profile_info</span><span style="color: #007700">;<br />    return </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div><?php manual_footer($setup); ?>