FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Home  »  WordPress  »  Prevent WP-Cache from Caching index

by 8 comments

A WordPress index page shouldn't be cached by wp-cache the same as posts or other pages not as frequently updated. This 30 second fix gives you control to not cache / or /index.php on your blog. You can use this hack to disable caching anything you want.



Disable caching specific URI's

First clear the cache from the WP-Cache Options Page. Then modify the wp_cache_is_rejected function.

  1. [ PRESS ] Delete cache on the WP-Cache Options Page
  2. [ OPEN ] wp-content/plugins/wp-cache/wp-cache-phase2.php
  3. [ FIND ] if (strstr($uri, '/wp-admin/'))
  4. [ REPLACE WITH ] if(strstr($uri,'/wp-admin/') || $uri==='/' || strstr($uri,'/index.php'))

NOTE: If anyone comes up with an improvement to this technique or a different/better implementation, please let me know so we can help with the development of an updated WP-Cache plugin!

WP-Cache Links

A WordPress index page shouldn't be cached by wp-cache the same as
posts or other pages not as frequently updated. This 30 second fix gives you control to not cache / or /index.php on your blog. You can use this hack to disable caching
anything you want.

Attached Files

  1. WP-Cache Version 2.1.1

Modified wp_cache_is_rejected function

function wp_cache_is_rejected($uri) {
  global $cache_rejected_uri;
 
  if(strstr($uri,'/wp-admin/') || $uri==='/' || strstr($uri,'/index.php'))
    return true; //we don't allow cacheing wp-admin for security
  foreach ($cache_rejected_uri as $expr) {
    if (strlen($expr) > 0 && strstr($uri, $expr))
      return true;
  }
  return false;
}

About WP-Cache Caching Plugin

WP-Cache works by caching WordPress pages and storing them in a static file for serving future requests directly from the file rather than loading and compiling the whole PHP code and the building the page from the database...

Wp-Cache uses 2 phases

The first is called at the very begining wp-cache-phase1.php when just few code has been compiled. The second wp-cache-phase2.php after all plugins have been executed. The first phase checks if the requested URL is already cached, if so it serves from the static file and finishes. The second phase stores the generated page in a static file for further request.

Tags

December 7th, 2007

Comments Welcome

  • http://www.wpproject.com Richard H

    Hey AA... I've been reading your material for several months --you've helped a lot with my various projects along the way. Thank you!

    I haven't tested this plugin yet, but I presume Wp-Cache would also affect the post comments?

    For example, 5 people have commented on post #39, but they're seeing a cached page, so the latest comments would not be shown.

    Is this correct?

  • http://www.askapache.com/ AskApache

    @ Richard

    Yes this plugin takes care of it by refreshing the cache when a comment/edit/etc. happens to the post.

    If I was only allowed to have one plugin, this would be it.

  • http://www.wpproject.com Richard H

    Thanks. Looking forward to the updated WP-Cache plugin.

  • ivanhoe

    is this mod-rewrite safe? Since if using pretty urls are being used everything goes to index.php, will it really disable just a home page?

  • http://www.askapache.com/ AskApache

    @ ivanhoe

    Yes, at least when using pretty-urls with mod_rewrite. mod_rewrite takes care of the redirection/rewriting of * to /index.php transparently, so the $uri seen by wp-cache is the same $uri seen in the browser.

  • http://www.artsy.ca/ Alex Kessaris

    Thank you! It's really funny because WP Super Cache (based on WP Cache) has an input field to accept rejected paths, but it's impossible to input / or index.php into it!

  • http://www.tgspot.co.il Itai

    Nice. i looking for this solution.

  • http://nicoblog-games.com/ Nico

    i've done this i hope it works

My Online Tools
WordPress Sites

My Picks

Related Articles
Newest Posts
Twitter

  • The Hacker Playbook - very nice high level overview of attacks  t.co/lHwNVWi61u 
  • Clean Code - A Handbook of Agile Software Craftsmanship  t.co/hnJX0x1qIc 
  • Secrets of the JavaScript Ninja - By my absolute favorite JS hacker John Resig!  t.co/tZ42ljmcCl 
  • Hacking Exposed 7: Network Security Secrets & SolutionsMy all time favorite, basic but thorough and accurate.  t.co/jycW0RDVtZ 
  • Empty words will be no surrogate for cold resolve. Pain is nothing.  t.co/qXjpRxbjCw 
  • REVERSING: Secrets of Reverse Engineering  t.co/GaWo29lWWG 
  • NEUROMANCER  t.co/3OoknUcb5Z 
  • "The Shockwave Rider", by John Brunner (1975 hacker sci-fi)  t.co/ZW56HVUefW 
  • The Rootkit ARSENAL - Escape and Evasion in the Dark Corners of the System  t.co/1FzX6bHgsQ 
  • "We Are Anonymous - Inside the Hacker World of LulzSec, Anonymous, and the Global Cyber Insurgency" better be good!  t.co/GL0cFNiUOq 
  • THE IDEA FACTORY Bell Labs  t.co/FyVhgNwwT5 
  • The Datacenter as a Computer -- Urs Holzle  t.co/M5WIYs1OVg 
  • Now by Steven Levy, "IN THE PLEX"  t.co/PwxtLgqukG 
  • Dreaming in code.... So far, a little boring, but worth the read  t.co/hmeeOjIlfg 

Friends and Recommends
Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman






[hide]

It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

| Google+ | askapache

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain