<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<refentry id="function.Memcache-set">
 <refnamediv>
  <refname>Memcache::set</refname>
  <refpurpose>Store data at the server</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>bool</type><methodname>Memcache::set</methodname>
   <methodparam><type>string</type><parameter>key</parameter></methodparam>
   <methodparam><type>mixed</type><parameter>var</parameter></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>flag</parameter></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>expire</parameter></methodparam>
  </methodsynopsis>

  <para>
   <function>Memcache::set</function> stores an item 
   <parameter>var</parameter> with <parameter>key</parameter> on the 
   memcached server. Parameter <parameter>expire</parameter> is expiration 
   time in seconds. If it's 0, the item never expires (but memcached server 
   doesn't guarantee this item to be stored all the time, it could be deleted 
   from the cache to make place for other items).
   You can use <constant>MEMCACHE_COMPRESSED</constant> constant as 
   <parameter>flag</parameter> value if you want to use on-the-fly
   compression (uses zlib).
   <note>
    <para>
     Remember that resource variables (i.e. file and connection descriptors)
     cannot be stored in the cache, because they cannot be adequately
     represented in serialized state.
    </para> 
   </note>
   Also you can use <function>memcache_set</function> function.
  </para>

 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>key</parameter></term>
     <listitem>
      <para>
       The key that will be associated with the item.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>var</parameter></term>
     <listitem>
      <para>
       The variable to store. Strings and integers are stored as is, other
       types are stored serialized.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>flag</parameter></term>
     <listitem>
      <para>
       Use <constant>MEMCACHE_COMPRESSED</constant> to store the item
       compressed (uses zlib).
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>expire</parameter></term>
     <listitem>
      <para>
       Expiration time of the item. If it's equal to zero, the item will never
       expire. You can also use unix timestamp or a number of seconds starting
       from current time, but in the latter case the number of seconds may not
       exceed 2592000 (30 days).
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>
 
 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.success;
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>Memcache::set</function> example</title>
    <programlisting role="php">
<![CDATA[
<?php
/* procedural API */

/* connect to memcached server */
$memcache_obj = memcache_connect('memcache_host', 11211);

/*
set value of item with key 'var_key'
using 0 as flag value, compression is not used
expire time is 30 seconds
*/
memcache_set($memcache_obj, 'var_key', 'some variable', 0, 30);

echo memcache_get($memcache_obj, 'var_key');

?>
]]>
    </programlisting>
   </example>
   <example>
    <title><function>Memcache::set</function> example</title>
    <programlisting role="php">
<![CDATA[
<?php
/* OO API */

$memcache_obj = new Memcache;

/* connect to memcached server */
$memcache_obj->connect('memcache_host', 11211);

/*
set value of item with key 'var_key', using on-the-fly compression
expire time is 50 seconds
*/
$memcache_obj->set('var_key', 'some really big variable', MEMCACHE_COMPRESSED, 50);

echo $memcache_obj->get('var_key');

?>
]]>
    </programlisting>
   </example>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>Memcache::add</function></member>
    <member><function>Memcache::replace</function></member>
   </simplelist>
  </para>
 </refsect1>
</refentry>

<!-- 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:"../../../../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
-->