<?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>WP Engineer &#187; cache</title>
	<atom:link href="http://wpengineer.com/tag/cache/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Sun, 22 Jan 2012 13:32:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple Cache with the WordPress Transient API</title>
		<link>http://wpengineer.com/2148/simple-cache-with-the-wordpress-transient-api/</link>
		<comments>http://wpengineer.com/2148/simple-cache-with-the-wordpress-transient-api/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 15:47:21 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2148</guid>
		<description><![CDATA[Today is our last post of our Advents Calendar, we hope you enjoyed it. WP Engineer wishes a Merry Christmas to our readers! WordPress has an API that is explicitly designed for time-controlled storage of data - the Transient API. This API is designed to cache any data in the database and very simple to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-2010-24.jpg" alt="" title="WordPress-Christmas-2010-24" width="400" height="267" class="aligncenter size-full wp-image-2172" /></p>
<p>Today is our last post of our Advents Calendar, we hope you enjoyed it. WP Engineer wishes a Merry Christmas to our readers!</p>
<p>WordPress has an API that is explicitly designed for time-controlled storage of data - the <a href="http://codex.wordpress.org/Transients_API">Transient API</a>. This API is designed to cache any data in the database and very simple to use it.<br />
<span id="more-2148"></span><br />
The first step is to get the entry from the database that will serve as content for the tag cloud - <code>$tag_cloud = get_transient( 'tag_cloud' );</code>. If this entry is missing, then the tag cloud is normally produced by the template <code>wp_tag_cloud()</code>. The only difference from the "normal" use in the template of the theme, the direct output is set on <code>FALSE</code>, because we need it in a variable.<br />
In the following we will now set the entry in the database with the content and give a time value with it: <code>set_transient($transient, $value, $expiration);</code>. The time value, parameter three, is specified in seconds.<br />
Now only the value of the variable has to be output and it's done; from now gets the tag cloud the data from the cache, which exists for a period of 12 hours and then rebuilt.</p>
<pre>
$tag_cloud = get_transient( &#039;tag_cloud&#039; );
if ( false === $tag_cloud || &#039;&#039; === $tag_cloud ){
	$args = array(&#039;echo&#039; =&gt; false);
	$tag_cloud = wp_tag_cloud( $args );
	set_transient( &#039;tag_cloud&#039;, $tag_cloud, 60*60*12 );
}
echo $tag_cloud;
</pre>
<p>This small example illustrates the possibilities, the Transient API provides some additional functions, you can read about more in the <a href="http://codex.wordpress.org/Transients_API">Codex</a>.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2148/simple-cache-with-the-wordpress-transient-api/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Delete all Feed Cache via SQL in WordPress</title>
		<link>http://wpengineer.com/2114/delete-all-feed-cache-via-sql-in-wordpress/</link>
		<comments>http://wpengineer.com/2114/delete-all-feed-cache-via-sql-in-wordpress/#comments</comments>
		<pubDate>Sat, 11 Dec 2010 11:25:10 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2114</guid>
		<description><![CDATA[The Feed-Cache of WordPress is in the database, it's in the table options and sometimes you like to delete it. With a little SQL this is done quite quickly - but be careful, there is no way back! Within WordPress I do it with the help of the Plugin Adminer, which allows a complete mySQL [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-2010-11.jpg" alt="" title="WordPress-Christmas-2010-11" width="400" height="267" class="aligncenter size-full wp-image-2127" /><br />
The Feed-Cache of WordPress is in the database, it's in the table <code>options</code> and sometimes you like to delete it. With a little SQL this is done quite quickly - but be careful, there is no way back! Within WordPress I do it with the help of the Plugin <a href="http://wordpress.org/extend/plugins/adminer/">Adminer</a>, which allows a complete mySQL access and you are still able to work in the backend of WordPress. Alternatively it's also possible with phpMyAdmin for example.<br />
<span id="more-2114"></span><br />
<img src="http://wpengineer.com/wp-content/uploads/sql-feedcache.png" alt="" title="sql-feedcache" width="634" height="177" class="aligncenter size-full wp-image-2115" /></p>
<p>With the help of the following syntax you can delete the cache very fast, you have to adjust the example prefix <code>wp_</code> of course.</p>
<pre>
DELETE FROM `wp_options` WHERE `option_name` LIKE (&#039;_transient%_feed_%&#039;)
</pre>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2114/delete-all-feed-cache-via-sql-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Feed Cache in WordPress</title>
		<link>http://wpengineer.com/1820/feed-cache-in-wordpress/</link>
		<comments>http://wpengineer.com/1820/feed-cache-in-wordpress/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 10:11:53 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[Constants]]></category>
		<category><![CDATA[Feed]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1820</guid>
		<description><![CDATA[WordPress already offers the possibility of own functions to read feeds and use it in your blog. Since version 2.8 of WordPress, a new feature is in use for that. So there are two ways to work with feeds in WordPress, and in both functions, the data is cached. But this is not always wanted, [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress already offers the possibility of own functions to read feeds and use it in your blog. Since version 2.8 of WordPress, a new feature is in use for that. So there are two ways to work with feeds in WordPress, and in both functions, the data is cached. But this is not always wanted, so I show how to take influence on caching of the two functions.<br />
<span id="more-1820"></span></p>
<h3>fetch_feed() <em>Since WordPress 2.8</em></h3>
<p>With version 2.8 of WordPress, they add the class <strong>SimplePie</strong> into the core. SimplePie has always distinguished by a very rapid development and a stable user-friendly class. Before <strong>MagpieRSS</strong> has been used, which in many cases was not available and the development is rather slow. For some time SimplePie is no longer be maintained by the developer, which worried the developer community. But developers from the WordPress team took care of it and keep the class alive. More information can be find on the blog <a href="http://wpdevel.wordpress.com/2009/09/24/suggest-agenda-items-for-oct-1st-dev-cha/">WP Dev Updates</a></p>
<p>Now the class is in the core of WordPress and is capable of generating RSS and ATOM feeds. It uses the cache of WordPress and can be controlled via a hook.</p>
<p>But first a small sample to read a feed with the class in WordPress.</p>
<pre lang="php">
&lt;?php
include_once(ABSPATH . WPINC . &#039;/feed.php&#039;);
$rss = fetch_feed(&#039;http://bueltge.de/feed/&#039;);
$rss_items = $rss-&gt;get_items( 0, $rss-&gt;get_item_quantity(5) );
if ( !$rss_items ) {
    echo &#039;no items&#039;;
} else {
    foreach ( $rss_items as $item ) {
        echo &#039;&lt;p&gt;&lt;a href=&quot;&#039; . $item-&gt;get_permalink() . &#039;&quot;&gt;&#039; . $item-&gt;get_title() . &#039;&lt;/a&gt;&lt;/p&gt;&#039;;
    }
}
?&gt;
</pre>
<p>The small sample reads my feed and returns the last 5 entries.</p>
<p>Essential is the function <code>fetch_feed()</code>. This function has a hook which can make influence on caching - <code>wp_feed_cache_transient_lifetime</code>.<br />
The standard of the cache is set to 12 hours (<code> 43,200 </code>), which is not always the favorite setting for users. The value is operated on the method <code>WP_Feed_Cache_Transient()</code>, parameter <code>$lifetime</code>. Therefore, it is advisable to use the following little query, be it in the Plugin or in the <code>functions.php</code> of the theme.</p>
<pre lang="php">
add_filter( &#039;wp_feed_cache_transient_lifetime&#039;, create_function( &#039;$a&#039;, &#039;return 1800;&#039; ) );
</pre>
<p>In this example, I set the cache to 30 minutes. With the help of <a href="http://codex.wordpress.org/Conditional_Tags">Conditional Tags</a> you can control the whole of it so that the cache-hook is only activated when you click on a page (<code>is_page()</code>) or for example you are in the front end (<code>!is_admin()</code>) of the blog. Here you must simply use the opportunities and adapt to your own needs.</p>
<p>A small possibility I would like to point out more, <strong>available as of WordPress 2.9</strong> (<a href="http://core.trac.wordpress.org/ticket/11117">ticket 11117</a>), to simplify debugging for developers. Thus, the cache is disabled in the environment, if the constant <code>WP_DEBUG</code> is set, which can be important now and then. Setting the constant is usually done in the <code>wp-config.php</code> of the installation, or as alternative in the Plugin.</p>
<pre lang="php">
function do_not_cache_feeds(&amp;$feed) {
	$feed-&gt;enable_cache(false);
}

if ( defined(&#039;WP_DEBUG&#039;) &amp;&amp; WP_DEBUG )
	add_action( &#039;wp_feed_options&#039;, &#039;do_not_cache_feeds&#039; );
</pre>
<h3>fetch_rss()</h3>
<p>Another function is <code>fetch_rss()</code>, which was set with WordPress 2.8 on the suspense list. As an alternative, the above function is active. Current is <code>fetch_rss()</code> still available and is also supported. Therefore, for completeness, also the possibility to influence the cache.</p>
<p>Here an example to read feed and output the last 5 entries of the feed</p>
<pre lang="php">
&lt;?php
include_once(ABSPATH . WPINC . &#039;/rss.php&#039;);
$rss = fetch_rss(&#039;http://bueltge.de/feed/&#039;);
$rss_items = array_slice($rss-&gt;items, 0, 5);
if ( empty($rss_items) ) {
    echo &#039;no items&#039;;
} else {
    foreach ( $rss_items as $item ) {
        echo &#039;&lt;p&gt;&lt;a href=&quot;&#039; . $item&#091;&#039;link&#039;&#093; . &#039;&quot;&gt;&#039; . $item&#091;&#039;title&#039;&#093; . &#039;&lt;/a&gt;&lt;/p&gt;&#039;;
    }
}
?&gt;
</pre>
<p>Here, the function <code>fetch_rss()</code> is used for reading and the cache can be changed via the constants. This must defined either directly in <code>wp-config.php</code> where they will apply globally to all applications, or you need to integrate them into its own functions.</p>
<pre lang="php">
define(&#039;MAGPIE_CACHE_ON&#039;, 0); // deactivate cache
define(&#039;MAGPIE_CACHE_AGE&#039;, 60*60) // Cache 1 hour in seconds
</pre>
<h3>Conclusion</h3>
<p>Since WordPress decided not to support MagpieRSS any longer in the future, you should only deal with SimplePie and not with the second possibility.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1820/feed-cache-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

