<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.2 $ --> <refentry id="function.Memcache-set"> <refnamediv> <refname>Memcache::set</refname> <refpurpose>Store data at the server</refpurpose> </refnamediv> <refsect1> <title>Description</title> <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). </para> <para> You can use <constant>MEMCACHE_COMPRESSED</constant> constant as <parameter>flag</parameter> value if you want to use on-the-fly compression (uses zlib). </para> <para> Also you can use <function>memcache_set</function> function. See example below. </para> <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> <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> &return.success; </para> <para> See also <function>Memcache::add</function>, <function>Memcache::replace</function>. </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 -->