<?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>Dev4Press&#187; megabytes Tag Archives, page 1 of 1 | Dev4Press</title>
	<atom:link href="http://www.dev4press.com/tag/megabytes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dev4press.com</link>
	<description>Premium Plugins and Themes for WordPress</description>
	<lastBuildDate>Sat, 25 May 2013 18:50:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Internal objects cache in WordPress</title>
		<link>http://www.dev4press.com/2010/tutorials/wordpress/practical/internal-object-cache-in-wordpress/</link>
		<comments>http://www.dev4press.com/2010/tutorials/wordpress/practical/internal-object-cache-in-wordpress/#comments</comments>
		<pubDate>Sun, 05 Sep 2010 14:38:24 +0000</pubDate>
		<dc:creator>MillaN</dc:creator>
				<category><![CDATA[Practical]]></category>
		<category><![CDATA[attempts]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[class instance]]></category>
		<category><![CDATA[database object]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[internal cache]]></category>
		<category><![CDATA[megabytes]]></category>
		<category><![CDATA[memory problems]]></category>
		<category><![CDATA[object cache]]></category>
		<category><![CDATA[object queries]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[xml file]]></category>

		<guid isPermaLink="false">http://www.dev4press.com/?p=3101</guid>
		<description><![CDATA[To speed things up, WordPress uses internal caching methods for storing object, queries for potential reuse. Use of cache will speed up normal operations of WordPress. Bot, there are cases where use of cache is not wanted and can cause tons of problems.]]></description>
				<content:encoded><![CDATA[<p>To speed things up, WordPress uses internal caching methods for storing object, queries for potential reuse. Use of cache will speed up normal operations of WordPress. Bot, there are cases where use of cache is not wanted and can cause tons of problems.</p>
<h3>How the internal cache works?</h3>
<p>Whenever WordPress runs function(s) that get posts, pages, categories or any other data object, result is than stored in instance of the <strong>WP_Object_Cache</strong> class. Each object is stored in it&#8217;s own group and it&#8217;s identified by ID. So, if you get post ID 1, it will be stored in this class instance. Next time on the same page, you need again same post, WP will search for it in the cache, and if it&#8217;s there it will get it for you, if not SQL query will be run to get it. Depending on number of stored objects, this cache can grow significantly.</p>
<p>Instance  of class <strong>WP_DB</strong> is main database object, and also stores all SQL queries executed through it. Most WP pages run 10 to 200 or so queries, and queries are stored as strings. With small number of queries this object can grow to couple of megabytes. For this object you can disable saving queries, but in many cases plugins will enable it, so you can&#8217;t be sure really that queries are not stored.</p>
<p>And all this is great if you only have code to generate pages, normal admin use, in fact normal use of  WordPress. If you have couple of hundreds or even thousands of posts/pages, none of the normal WP operations will cause problems with use of cache. But, what if you have website with 200.000 or more posts?</p>
<h3>Out of memory problems</h3>
<p>For large websites, first piece of code that will fail even if you use <strong>256M</strong> for PHP is <strong>Google XML Sitemaps</strong> plugin when attempts to make a XML file. To get URL for each post, it will run <strong>get_permalink() </strong>function, that is running <strong>get_post()</strong> that is caching objects. So, each post will be cached even if it&#8217;s used only once. And when plugin reaches 70.000 posts (approx.), PHP will run out of memory, and all 256M will be used! Not only posts, but all SQL queries will be stored. And for 70.000 posts, in this case WP can run more than 100.000 queries.</p>
<p>I am working on website that has 300.000 posts, sitemap generating  crashes at 65.000 with 256M used up. So, I made a new code that controls sitemap: splits sitemap in new file at every 50.000 posts (Google limit per sitemap is 50.000), and also is clearing cached data to prevent out of control use of memory.</p>
<h3>Solution for clearing cache</h3>
<p>Website I work on has several cleanup and processing operations that will generate large amount of queries and cache many objects during each run. Using cache will break it for sure on every run. But, in WordPress right now there is no way to disable cache. It would be good that directive like WP_DISABLE_CACHE is added to control this. And until that is done, only way to control it is actually to delete cached object. So, my processing code and also sitemaps code is using simple function to clear cache from time to time.</p>
<p>Here is the function that will clear cache object and stored queries:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
function wp_clean_cache_full() {
  global $wpdb, $wp_object_cache;

  unset($wp_object_cache-&gt;cache);
  $wp_object_cache-&gt;cache = array();
  unset($wpdb-&gt;queries);
  $wpdb-&gt;queries = array();
}
?&gt;</pre>
<h3>Conclusion</h3>
<p>This is not something that you will need all the time, but it&#8217;s good thing to know what can cause website crashes that you can&#8217;t understand at first. Out of memory problems are common with large websites if the data is not handled properly.</p>
<script src="http://feeds.feedburner.com/~s/adsense@gdragon.info?i=http://www.dev4press.com/2010/tutorials/wordpress/practical/internal-object-cache-in-wordpress/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://www.dev4press.com/2010/tutorials/wordpress/practical/internal-object-cache-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk: enhanced
Content Delivery Network via cdn.dev4press.com

 Served from: www.dev4press.com @ 2013-05-26 06:33:41 by W3 Total Cache -->