<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.apcu.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.apcu-entry.php',
    1 => 'apcu_entry',
    2 => 'Atomically fetch or generate a cache entry',
  ),
  'up' => 
  array (
    0 => 'ref.apcu.php',
    1 => 'APCu Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.apcu-enabled.php',
    1 => 'apcu_enabled',
  ),
  'next' => 
  array (
    0 => 'function.apcu-exists.php',
    1 => 'apcu_exists',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/apcu/functions/apcu-entry.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.apcu-entry" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">apcu_entry</h1>
  <p class="verinfo">(PECL apcu &gt;= 5.1.0)</p><p class="refpurpose"><span class="refname">apcu_entry</span> &mdash; <span class="dc-title">
   Atomically fetch or generate a cache entry
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.apcu-entry-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>apcu_entry</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$key</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$ttl</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="simpara">
   Atomically attempts to find <code class="parameter">key</code> in the cache, if it cannot be found <code class="parameter">callback</code>
   is called, passing <code class="parameter">key</code> as the only argument. The return value of the call is then cached with the optionally specified
   <code class="parameter">ttl</code>, and returned.
  </p>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <span class="simpara">
    When control enters <span class="function"><strong>apcu_entry()</strong></span> the lock for the cache is acquired exclusively, it is released when control leaves <span class="function"><strong>apcu_entry()</strong></span>:
    In effect, this turns the body of <code class="parameter">callback</code> into a critical section, disallowing two processes from executing the same code paths concurrently.
    In addition, it prohibits the concurrent execution of any other APCu functions, since they will acquire the same lock.
   </span>
  </p></blockquote>
  <div class="warning"><strong class="warning">Warnung</strong>
   <p class="simpara">
    The only APCu function that can be called safely by <code class="parameter">callback</code> is <span class="function"><strong>apcu_entry()</strong></span>.
   </p>
  </div>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.apcu-entry-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
    <dt><code class="parameter">key</code></dt>
    <dd>
     <span class="simpara">
      Identity of cache entry
     </span>
    </dd>
   
   
    <dt><code class="parameter">callback</code></dt>
    <dd>
     <span class="simpara">
      A callable that accepts <code class="parameter">key</code> as the only argument and returns the value to cache.
     </span>
    </dd>
   
   
    <dt><code class="parameter">ttl</code></dt>
    <dd>
     <span class="simpara">
      Time To Live; store the <code class="parameter">callback</code>&#039;s return value in the cache for
      <code class="parameter">ttl</code> seconds. After the
      <code class="parameter">ttl</code> has passed, the stored entry will be
      expunged from the cache (on the next request). If no <code class="parameter">ttl</code>
      is supplied (or if the <code class="parameter">ttl</code> is
      <code class="literal">0</code>), the value will persist until it is removed from
      the cache manually, or otherwise fails to exist in the cache (clear,
      restart, etc.).
     </span>
    </dd>
   
  </dl>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.apcu-entry-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="simpara">
   Returns the cached value
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.apcu-entry-examples">
  <h3 class="title">Beispiele</h3>
  <div class="example" id="example-1">
   <p><strong>Beispiel #1 An <span class="function"><strong>apcu_entry()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$config </span><span style="color: #007700">= </span><span style="color: #0000BB">apcu_entry</span><span style="color: #007700">(</span><span style="color: #DD0000">"config"</span><span style="color: #007700">, function(</span><span style="color: #0000BB">$key</span><span style="color: #007700">) {<br /> return [<br />   </span><span style="color: #DD0000">"fruit" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">apcu_entry</span><span style="color: #007700">(</span><span style="color: #DD0000">"config.fruit"</span><span style="color: #007700">, function(</span><span style="color: #0000BB">$key</span><span style="color: #007700">){<br />     return [<br />       </span><span style="color: #DD0000">"apples"</span><span style="color: #007700">,<br />       </span><span style="color: #DD0000">"pears"<br />     </span><span style="color: #007700">];<br />   }),<br />   </span><span style="color: #DD0000">"people" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">apcu_entry</span><span style="color: #007700">(</span><span style="color: #DD0000">"config.people"</span><span style="color: #007700">, function(</span><span style="color: #0000BB">$key</span><span style="color: #007700">){<br />     return [<br />      </span><span style="color: #DD0000">"bob"</span><span style="color: #007700">,<br />      </span><span style="color: #DD0000">"joe"</span><span style="color: #007700">,<br />      </span><span style="color: #DD0000">"niki"<br />     </span><span style="color: #007700">];<br />   })<br /> ];<br />});<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">array(2) {
  [&quot;fruit&quot;]=&gt;
  array(2) {
    [0]=&gt;
    string(6) &quot;apples&quot;
    [1]=&gt;
    string(5) &quot;pears&quot;
  }
  [&quot;people&quot;]=&gt;
  array(3) {
    [0]=&gt;
    string(3) &quot;bob&quot;
    [1]=&gt;
    string(3) &quot;joe&quot;
    [2]=&gt;
    string(4) &quot;niki&quot;
  }
}</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.apcu-entry-seealso">
  <h3 class="title">Siehe auch</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.apcu-store.php" class="function" rel="rdfs-seeAlso">apcu_store()</a> - Cache a variable in the data store</span></li>
   <li><span class="function"><a href="function.apcu-fetch.php" class="function" rel="rdfs-seeAlso">apcu_fetch()</a> - Fetch a stored variable from the cache</span></li>
   <li><span class="function"><a href="function.apcu-delete.php" class="function" rel="rdfs-seeAlso">apcu_delete()</a> - Removes a stored variable from the cache</span></li>
  </ul>
 </div>


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