Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 6582

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Adds a variable in user cache only if variable does not already exist in the cache</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.wincache-scache-meminfo.html">wincache_scache_meminfo</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.wincache-ucache-cas.html">wincache_ucache_cas</a></div>
 <div class="up"><a href="ref.wincache.html">WinCache Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.wincache-ucache-add" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">wincache_ucache_add</h1>
  <p class="verinfo">(PECL wincache &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">wincache_ucache_add</span> &mdash; <span class="dc-title">
   Adds a variable in user cache only if variable does not already exist in the cache
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.wincache-ucache-add-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>wincache_ucache_add</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$ttl</code><span class="initializer"> = 0</span></span>
  ] )</div>

  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>wincache_ucache_add</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$values</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$unused</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$ttl</code><span class="initializer"> = 0</span></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Adds a variable in user cache, only if this variable doesn&#039;t already exist in the cache. 
   The added variable remains in the user cache unless its time to live expires or it is 
   deleted by using  <span class="function"><a href="function.wincache-ucache-delete.html" class="function">wincache_ucache_delete()</a></span> or  <span class="function"><a href="function.wincache-ucache-clear.html" class="function">wincache_ucache_clear()</a></span> functions.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.wincache-ucache-add-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">key</code></em></span>
     <dd>

      <p class="para">
       Store the variable using this <em><code class="parameter">key</code></em> name. If a variable with same key is already present the function
       will fail and return <strong><code>FALSE</code></strong>. <em><code class="parameter">key</code></em> is case sensitive. To override the value even if 
       <em><code class="parameter">key</code></em> is present use  <span class="function"><a href="function.wincache-ucache-set.html" class="function">wincache_ucache_set()</a></span> function instad. 
       <em><code class="parameter">key</code></em> can also take array of name =&gt; value pairs where names will be used as keys. 
       This can be used to add multiple values in the cache in one operation, thus avoiding race condition.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">value</code></em></span>
     <dd>

      <p class="para">
       Value of a variable to store. <em><code class="parameter">Value</code></em> supports all data types except resources, such as file handles.
       This paramter is ignored if first argument is an array. A general guidance is to pass <strong><code>NULL</code></strong> 
       as <em><code class="parameter">value</code></em> while using array as <em><code class="parameter">key</code></em>. If <em><code class="parameter">value</code></em> is an
       object, or an array containing objects, then the objects will be serialized. See
       <a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a> for details on serializing objects.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">values</code></em></span>
     <dd>

      <p class="para">
       Associative array of keys and values.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">ttl</code></em></span>
     <dd>

      <p class="para">
       Time for the variable to live in the cache in seconds. After the value specified in <em><code class="parameter">ttl</code></em> has passed 
       the stored variable will be deleted from the cache. This parameter takes a default value of <em>0</em> which means 
       the variable will stay in the cache unless explicitly deleted by using  <span class="function"><a href="function.wincache-ucache-delete.html" class="function">wincache_ucache_delete()</a></span> 
       or  <span class="function"><a href="function.wincache-ucache-clear.html" class="function">wincache_ucache_clear()</a></span> functions.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.wincache-ucache-add-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   If <em><code class="parameter">key</code></em> is string, the function returns <strong><code>TRUE</code></strong> on success and <strong><code>FALSE</code></strong> on failure.
  </p>
  <p class="para">
   If <em><code class="parameter">key</code></em> is an array, the function returns:
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      If all the name =&gt; value pairs in the array can be set, function returns an empty array;
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
     If all the name =&gt; value pairs in the array cannot be set, function returns <strong><code>FALSE</code></strong>;
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      If some can be set while others cannot, function returns an array with name=&gt;value pair for which the addition failed in the user cache.
     </span>
    </li>
   </ul>
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.wincache-ucache-add-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-569">
    <p><strong>Example #1  <span class="function"><strong>wincache_ucache_add()</strong></span> with <em><code class="parameter">key</code></em> as a string</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'BAR'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">wincache_ucache_add</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bar</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">wincache_ucache_add</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bar</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">wincache_ucache_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
bool(true)
bool(false)
string(3) &quot;BAR&quot; 
</pre></div>
    </div>    
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-570">
    <p><strong>Example #2  <span class="function"><strong>wincache_ucache_add()</strong></span> with <em><code class="parameter">key</code></em> as an array</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$colors_array&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'green'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'5'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Blue'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'6'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'yellow'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'7'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'cyan'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'8'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">wincache_ucache_add</span><span style="color: #007700">(</span><span style="color: #0000BB">$colors_array</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">wincache_ucache_add</span><span style="color: #007700">(</span><span style="color: #0000BB">$colors_array</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">wincache_ucache_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'Blue'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(0) { } 
array(4) { 
  [&quot;green&quot;]=&gt; int(-1) 
  [&quot;Blue&quot;]=&gt; int(-1) 
  [&quot;yellow&quot;]=&gt; int(-1) 
  [&quot;cyan&quot;]=&gt; int(-1) 
} 
string(1) &quot;6&quot;
</pre></div>
    </div>    
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.wincache-ucache-add-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.wincache-ucache-set.html" class="function" rel="rdfs-seeAlso">wincache_ucache_set()</a> - Adds a variable in user cache and overwrites a variable if it already exists in the cache</span></li>
    <li class="member"> <span class="function"><a href="function.wincache-ucache-get.html" class="function" rel="rdfs-seeAlso">wincache_ucache_get()</a> - Gets a variable stored in the user cache</span></li>
    <li class="member"> <span class="function"><a href="function.wincache-ucache-delete.html" class="function" rel="rdfs-seeAlso">wincache_ucache_delete()</a> - Deletes variables from the user cache</span></li>
    <li class="member"> <span class="function"><a href="function.wincache-ucache-clear.html" class="function" rel="rdfs-seeAlso">wincache_ucache_clear()</a> - Deletes entire content of the user cache</span></li>
    <li class="member"> <span class="function"><a href="function.wincache-ucache-exists.html" class="function" rel="rdfs-seeAlso">wincache_ucache_exists()</a> - Checks if a variable exists in the user cache</span></li>
    <li class="member"> <span class="function"><a href="function.wincache-ucache-meminfo.html" class="function" rel="rdfs-seeAlso">wincache_ucache_meminfo()</a> - Retrieves information about user cache memory usage</span></li>
    <li class="member"> <span class="function"><a href="function.wincache-ucache-info.html" class="function" rel="rdfs-seeAlso">wincache_ucache_info()</a> - Retrieves information about data stored in the user cache</span></li>
    <li class="member"><a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.wincache-scache-meminfo.html">wincache_scache_meminfo</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.wincache-ucache-cas.html">wincache_ucache_cas</a></div>
 <div class="up"><a href="ref.wincache.html">WinCache Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>