Caching of Feeds


#1

Oh hai!

I was wondering why the suggested nginx configuration prevents URLs containing “/feed/” from being cached. According to my access logs and a quick look at the code, these URLs are in fact purged, and while someone in this thread suggested removing the purging code, I would much rather do the opposite and allow feeds to be cached. Just the explicit exclusion in the sample config leads me to think that I may be overlooking a crucial problem with that approach.

# Don't cache uris containing the following segments  
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {  
    set $no_cache 1;  
}     

We have many readers who request our feeds frequently, so that almost 30% of the requests handled my Wordpress (cache notwithstanding) are requests for various feeds. The comment feeds of older posts hardly ever change anymore, and with just a few posts and updates per day, the main feeds would greatly benefit from caching as well.

Are there any hidden hazards in just removing the “|/feed/” part from the regular expression?

Many thanks in advance,

Telofy


#2

I noticed a problem. While …/feed/ is purged, …/feed/atom/ isn’t, and purging multiple location at once in nginx is not yet supported.

If it’s just a matter of adding another line here, I can provide a pull request.


#3

@Telofy

Feeds are cached to reduce loads. Feeds generally see non-human traffic from search engines, RSS readers, aggregators, etc.

Most WordPress caching plugins will refresh feed content as soon as a post is published/edited so you no need to worry about visitor getting stale content.

Regarding this issue, we are not developer of that nginx-module so I cannot tell you anything about pull-request.

But if you are using nginx-helper WordPress plugin, feel free to send pull requests (if you have any).


#4

Oh yes, sorry, I’m using the nginx-helper plugin and nginx FastCGI caching. Maybe I should’ve pointed that out.


#5

I forgot to mention yesterday that I also filed this pull request. I’ve applied it to our sites; let’s hope nothing explodes.


#6

Thanks for your pull-request. :-)

We will merge it and test it locally soon. If all works nicely, we will add & release it.

If you have account on wordpress.org, can you tell us your username there. So we can credit you as contributor in next release (assuming this will work nicely) ;-)


#7

Cool, thanks!

(I didn’t have an account, but now I do.)


#8

@Telofy

Your work is already released - http://wordpress.org/extend/plugins/nginx-helper/changelog/ :-)


#9

Yep, thankies! I already updated both sites earlier. :‑)


#10

Hi guys!

So, if I get this right Nginx Helper is actually purging all the feeds. But the config tells Nginx to bypass all the feeds?

# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
	set $skip_cache 1;
}

So I’d only need to remove /feed/ from there and It’ll automagically cache+purge, right?

Thanks!


#11