<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Optimizing Dynamic Content With Memcached</title>
	<atom:link href="http://dawnerd.com/articles/php/optimizing-dynamic-content-with-memcached/feed/" rel="self" type="application/rss+xml" />
	<link>http://dawnerd.com/articles/php/optimizing-dynamic-content-with-memcached/</link>
	<description>CSS / JavaScript / HTML5</description>
	<lastBuildDate>Thu, 10 Jun 2010 11:12:58 -0700</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Cameron Eure</title>
		<link>http://dawnerd.com/articles/php/optimizing-dynamic-content-with-memcached/comment-page-1/#comment-65</link>
		<dc:creator>Cameron Eure</dc:creator>
		<pubDate>Sat, 05 Jul 2008 18:03:28 +0000</pubDate>
		<guid isPermaLink="false">http://dawnerd.com/?p=16#comment-65</guid>
		<description>You could simplify that a bit, by doing:

$data = $memcache-&gt;get();
if (!data) {
    // Build $data
}

// Code Here

That way you don&#039;t have to fetch twice.

Also, in cases when your site doesn&#039;t get a lot of writes, you can cache the whole page, and set hooks in the administration panel to clear the cache on UPDATES/DELETES:

$data = $memcache-&gt;get($_SERVER[&#039;REQUEST_URI&#039;]);
if ($data) {
    // Cache Hit
    echo $data;
    die();
}

// Cache Miss
ob_start();
ob_implicit_flush(false);

// Your code goes here

$data = ob_get_contents();
$memcache-&gt;set($_SERVER[&#039;REQUEST_URI&#039;], $data);
ob_end_flush();</description>
		<content:encoded><![CDATA[<p>You could simplify that a bit, by doing:</p>
<p>$data = $memcache-&gt;get();<br />
if (!data) {<br />
    // Build $data<br />
}</p>
<p>// Code Here</p>
<p>That way you don&#8217;t have to fetch twice.</p>
<p>Also, in cases when your site doesn&#8217;t get a lot of writes, you can cache the whole page, and set hooks in the administration panel to clear the cache on UPDATES/DELETES:</p>
<p>$data = $memcache-&gt;get($_SERVER['REQUEST_URI']);<br />
if ($data) {<br />
    // Cache Hit<br />
    echo $data;<br />
    die();<br />
}</p>
<p>// Cache Miss<br />
ob_start();<br />
ob_implicit_flush(false);</p>
<p>// Your code goes here</p>
<p>$data = ob_get_contents();<br />
$memcache-&gt;set($_SERVER['REQUEST_URI'], $data);<br />
ob_end_flush();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: OXODesign TEAM</title>
		<link>http://dawnerd.com/articles/php/optimizing-dynamic-content-with-memcached/comment-page-1/#comment-60</link>
		<dc:creator>OXODesign TEAM</dc:creator>
		<pubDate>Fri, 04 Jul 2008 12:04:48 +0000</pubDate>
		<guid isPermaLink="false">http://dawnerd.com/?p=16#comment-60</guid>
		<description>Some more optimize:

function mcQuery($sql_query, $key){
	global $mc;
	$result = $mc-&gt;get($key);
	if(!$result){
		$rs = mysql_query($sql_query);
		if(mysql_num_rows($row)){
			while($row = mysql_fetch_array($rs))
				$result[] = $row;
		
			$memcache-&gt;set($key,$result, 0, 3600);
		}
	}
	
	return $result;
}

$mc = new Memcache;
$mc-&gt;connect(&#039;memcache_host&#039;, 11211);

$rs = mcQuery(&#039;SELECT * FROM posts ORDER BY date LIMIT 5&#039;, &#039;recent_posts&#039;);
for($i=0;$i&lt;count($rs);$i++){
	echo &quot;&quot;.$rs[$i][&#039;title&#039;].&quot;&quot;;
}</description>
		<content:encoded><![CDATA[<p>Some more optimize:</p>
<p>function mcQuery($sql_query, $key){<br />
	global $mc;<br />
	$result = $mc-&gt;get($key);<br />
	if(!$result){<br />
		$rs = mysql_query($sql_query);<br />
		if(mysql_num_rows($row)){<br />
			while($row = mysql_fetch_array($rs))<br />
				$result[] = $row;</p>
<p>			$memcache-&gt;set($key,$result, 0, 3600);<br />
		}<br />
	}</p>
<p>	return $result;<br />
}</p>
<p>$mc = new Memcache;<br />
$mc-&gt;connect(&#8216;memcache_host&#8217;, 11211);</p>
<p>$rs = mcQuery(&#8216;SELECT * FROM posts ORDER BY date LIMIT 5&#8242;, &#8216;recent_posts&#8217;);<br />
for($i=0;$i&lt;count($rs);$i++){<br />
	echo &#8220;&#8221;.$rs[$i]['title'].&#8221;";<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
