<?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>dawnerd &#187; memcache</title>
	<atom:link href="http://dawnerd.com/tag/memcache/feed/" rel="self" type="application/rss+xml" />
	<link>http://dawnerd.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Fri, 13 Aug 2010 18:20:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using Memcached to Reduce Database Load</title>
		<link>http://dawnerd.com/post/6_using-memcached-to-reduce-database-load/</link>
		<comments>http://dawnerd.com/post/6_using-memcached-to-reduce-database-load/#comments</comments>
		<pubDate>Thu, 08 May 2008 05:00:00 +0000</pubDate>
		<dc:creator>Troy Whiteley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[server loads]]></category>

		<guid isPermaLink="false">http://dawnerd.com/?p=6</guid>
		<description><![CDATA[If you host your site on a shared server environment, then this information will not be useful for you (unless the shared server had memcached installed, which would be awesome). If you run a large website, you probably should be &#8230; <a href="http://dawnerd.com/post/6_using-memcached-to-reduce-database-load/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you host your site on a shared server environment, then this information will not be useful for you (unless the shared server had memcached installed, which would be awesome). <span id="more-6"></span></p>
<p>If you run a large website, you probably should be offsetting your database load. One popular solution is to cache database queries to files on the server&#8217;s hardrive. This is not the best way if you are looking for near instant data read times. Memcached stores data into ram, making reading and writing the data very quick.</p>
<p>A simple scenario: You increment the &#8216;views&#8217; field for a news post. All growing traffic causes a ton of updates which result in locking. Your site becomes slow. Memcached to the rescue!</p>
<pre>
<code markup="none">
$memcache = new Memcache;
$memcache->connect('memcache_host', 11211);
if(!$memcache->get('postxyz_123_views'))
{
    //sql to grab number of views

    //number expires in one hour
    $memcache->set('postxyz_123_views',$view_count, 0, 3600);
}
//increment the views
$memcache->increment('postxyz_123_views');

$view_count = $memcache->get('postxyz_123_views');
</code>
</pre>
<p>All you need to do then is run a cron job every hour and have it dump the view counts to the database.</p>
<p>That is basically all there is to using memcached. It is very simple. If you feel adventurous, check out the <a href="http://us.php.net/manual/en/ref.memcache.php">php documentation</a> for some more advanced features.</p>
]]></content:encoded>
			<wfw:commentRss>http://dawnerd.com/post/6_using-memcached-to-reduce-database-load/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
