Support » Plugins » WP Super Cache doesn’t cache 404s… should it?

  • Resolved Simon Wheatley

    (@simonwheatley)


    Code for the People

    Hi,

    Just wondering what the thinking behind WP Super Cache not caching 404 responses is? I can see no generic disadvantage to it doing so, although I suppose some themes might provide “helpful” dynamically generated 404 error pages. Perhaps a filter or option to allow caching of 404s might be handy?

    Here’s a patch I made to WPSC to allow caching of 404 requests:

    Index: /Users/simon/Projects/SF/trunk/site/wp-content/plugins/wp-super-cache/wp-cache-phase2.php
    ===================================================================
    --- /Users/simon/Projects/SF/trunk/site/wp-content/plugins/wp-super-cache/wp-cache-phase2.php	(revision 2566)
    +++ /Users/simon/Projects/SF/trunk/site/wp-content/plugins/wp-super-cache/wp-cache-phase2.php	(working copy)
    @@ -251,7 +251,7 @@
    
     	/* Mode paranoic, check for closing tags
     	 * we avoid caching incomplete files */
    -	if( $wp_cache_404 ) {
    +	if( $wp_cache_404 && !apply_filters( 'supercache_404s', true ) ) {
     		$new_cache = false;
     		$buffer .= "\n<!-- Page not cached by WP Super Cache. 404. -->\n";
     	}

    S

Viewing 7 replies - 1 through 7 (of 7 total)
  • Just added that to trunk as the “wpsupercache_404” filter, but reversed the filter so that 404 pages are still not cached by default. Return true to supercache those pages. Thanks!

    Simon Wheatley

    (@simonwheatley)

    Code for the People

    Awesome, thanks Donncha!

    So in order to get this to work I should add

    <?php add_filer ('wpsupercache_404', '', '', 'true' ); ?>

    or

    apply_filters('supercache_404s', true );

    to functions.php?

    You need to use add_filter(), but not in the way you’ve tried above. That’s not how filters work. Google for “WordPress add_filter” and you’ll find out all you need to know!

    thanks, I´m reading that at the Codex.

    I went trough the Codex but couldn´t figure out how to do this so I could cache 404 pages… any help?

    This should do it:

    add_action ( ‘wpsupercache_404’, create_function ( ‘$a’ , “return true” ) );

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WP Super Cache doesn’t cache 404s… should it?’ is closed to new replies.