<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zend_Cache &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/zend_cache/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>A Memcached Zend_Cache</title>
		<link>/2011/01/17/a-memcached-zend_cache/</link>
		<comments>/2011/01/17/a-memcached-zend_cache/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 13:42:48 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[Computer memory]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Memcached]]></category>
		<category><![CDATA[MMCache]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Zend_Cache]]></category>

		<guid isPermaLink="false">/?p=2121</guid>
		<description><![CDATA[Zend_Cache Usually Zend_Cache is used to store cache files on the file system, which can be really fast and useful in most of the cases. However there&#8217;s a faster cache mechanism and hopefully it&#8217;s supported by Zend_Cache as well. This is the Memcached backend. A Faster Cache Memcached is a really powerful tool to cache &#8230; <a href="/2011/01/17/a-memcached-zend_cache/" class="more-link">Continue reading <span class="screen-reader-text">A Memcached Zend_Cache</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/01/27/theory-of-caching-zend_cache-zend-optimizer/" rel="bookmark" title="Theory of caching. Zend_Cache &#038; Zend Optimizer.">Theory of caching. Zend_Cache &#038; Zend Optimizer. </a></li>
<li><a href="/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/" rel="bookmark" title="How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies">How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/04/26/mysql-expressions-in-zend-framework/" rel="bookmark" title="MySQL Expressions in Zend Framework">MySQL Expressions in Zend Framework </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Zend_Cache</h2>
<p>Usually <a title="Zend_Cache" href="http://framework.zend.com/manual/en/zend.cache.html" target="_blank">Zend_Cache</a> is used to store cache files on the file system, which can be really fast and useful in most of the cases. However there&#8217;s a faster cache mechanism and hopefully it&#8217;s supported by Zend_Cache as well. This is the <a title="Memcached" href="http://memcached.org/" target="_blank">Memcached</a> backend.</p>
<h2>A Faster Cache</h2>
<p>Memcached is a really powerful tool to cache directly into the RAM. First, this tool has nothing to do primary with Zend Framework. It&#8217;s a server, usually started on some port, that can be called to store and get things from the memory. This of course is very fast, way faster than the cache in the hard drives.</p>
<h2>Zend_Cache and Memcached</h2>
<p>Zend_Cache has an interface to work with Memcached which is great as usual. The PHP example of Memcache (note that there are two things <a title="Memcache" href="http://php.net/manual/en/book.memcache.php" target="_blank">Memcache</a> and <a title="Memcached" href="http://memcached.org/" target="_blank">Memcached</a>, which are slight different) can be found here and as it says:</p>
<pre lang="php" escaped="true">
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";

var_dump($get_result);
</pre>
<p>However this can be coded into a Zend Framework style like that:</p>
<pre lang="php">
$frontend = array('caching' => true, 'lifetime' => 1800, 'automatic_serialization' => true);

$backend = array(
    'servers' =>array(
        array('host' => '127.0.0.1', 'port' => 11211)
    ),
    'compression' => false
);

$cache = Zend_Cache::factory('Core', 'Memcached', $frontend, $backend);
</pre>
<p>Note that you don&#8217;t have the typical &#8220;cache_dir&#8221;, just because everything&#8217;s cached into the memory.</p>
<p>Now you can call the cache as it&#8217;s called with the &#8220;File&#8221; backend interface:</p>
<pre lang="php">
$key = 'mykey';

if (($result = $cache->load($key)) === false) {
	// call the slow database query here ...
	// save in $result
	
	$cache->save($result, $key);	
}

echo $result
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/01/27/theory-of-caching-zend_cache-zend-optimizer/" rel="bookmark" title="Theory of caching. Zend_Cache &#038; Zend Optimizer.">Theory of caching. Zend_Cache &#038; Zend Optimizer. </a></li>
<li><a href="/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/" rel="bookmark" title="How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies">How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/04/26/mysql-expressions-in-zend-framework/" rel="bookmark" title="MySQL Expressions in Zend Framework">MySQL Expressions in Zend Framework </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/01/17/a-memcached-zend_cache/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
