mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 13:57:03 +08:00
199 lines
12 KiB
HTML
199 lines
12 KiB
HTML
<!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 and overwrites a variable if it already exists in the cache</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.wincache-ucache-set" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">wincache_ucache_set</h1>
|
|
<p class="verinfo">(PECL wincache >= 1.1.0)</p><p class="refpurpose"><span class="refname">wincache_ucache_set</span> — <span class="dc-title">
|
|
Adds a variable in user cache and overwrites a variable if it already exists in the cache
|
|
</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.wincache-ucache-set-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>wincache_ucache_set</strong></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">$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>
|
|
] ) : <span class="type">bool</span></div>
|
|
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>wincache_ucache_set</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 class="initializer"> = NULL</span></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$ttl</code><span class="initializer"> = 0</span></span>
|
|
]] ) : <span class="type">bool</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Adds a variable in user cache. Overwrites a variable if it already exists in the cache.
|
|
The added or updated variable remains in the user cache unless its time to live expires or it is
|
|
deleted by using <span class="function"><a href="wincache_ucache_delete.html" class="function">wincache_ucache_delete()</a></span> or <span class="function"><a href="wincache_ucache_clear.html" class="function">wincache_ucache_clear()</a></span> functions.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.wincache-ucache-set-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">key</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Store the variable using this <code class="parameter">key</code> name. If a variable with same
|
|
<code class="parameter">key</code> is already present the function will overwrite the previous
|
|
value with the new one. <code class="parameter">key</code> is case sensitive.
|
|
<code class="parameter">key</code> can also take array of name => 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>
|
|
<code class="parameter">value</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Value of a variable to store. <code class="parameter">Value</code> 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 <code class="parameter">value</code> while using array as <code class="parameter">key</code>. If <code class="parameter">value</code> 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>
|
|
<code class="parameter">values</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Associative array of keys and values.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">ttl</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Time for the variable to live in the cache in seconds. After the value specified in <code class="parameter">ttl</code> 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="wincache_ucache_delete.html" class="function">wincache_ucache_delete()</a></span>
|
|
or <span class="function"><a href="wincache_ucache_clear.html" class="function">wincache_ucache_clear()</a></span> functions.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.wincache-ucache-set-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="simpara">
|
|
If <code class="parameter">key</code> 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 <code class="parameter">key</code> is an array, the function returns:
|
|
<ul class="itemizedlist">
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
If all the name => 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 => 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=>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-set-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-634">
|
|
<p><strong>Example #1 <span class="function"><strong>wincache_ucache_set()</strong></span> with <code class="parameter">key</code> as a string</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$bar </span><span style="color: #007700">= </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_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">, </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">$bar1 </span><span style="color: #007700">= </span><span style="color: #DD0000">'BAR1'</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_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">, </span><span style="color: #0000BB">$bar1</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">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程会输出:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
bool(true)
|
|
string(3) "BAR"
|
|
bool(true)
|
|
string(3) "BAR1"
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
<p class="para">
|
|
<div class="example" id="example-635">
|
|
<p><strong>Example #2 <span class="function"><strong>wincache_ucache_set()</strong></span> with <code class="parameter">key</code> as an array</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$colors_array </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'green' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'5'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Blue' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'6'</span><span style="color: #007700">, </span><span style="color: #DD0000">'yellow' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'7'</span><span style="color: #007700">, </span><span style="color: #DD0000">'cyan' </span><span style="color: #007700">=> </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_set</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_set</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">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程会输出:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
array(0) {}
|
|
array(0) {}
|
|
string(1) "6"
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.wincache-ucache-set-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="wincache_ucache_add.html" class="function" rel="rdfs-seeAlso">wincache_ucache_add()</a> - Adds a variable in user cache only if variable does not already exist in the cache</span></li>
|
|
<li class="member"><span class="function"><a href="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="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="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="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="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="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></div></div></body></html> |