WordPress.org

Ready to get started?Download WordPress

Forums

WP Super Cache
Homepage not refreshing - Garbage Collection problem (23 posts)

  1. FolioVision
    Member
    Posted 2 years ago #

    Hello Donncha,

    we had issues with one of the sites, where the homepage was 5 days old, even though there were new posts every day. I was checking for possible plugin conflicts and so on.

    I noticed that when the plugin is installed, the Garbage Collector event wp_cache_gc is scheduled only as a "One-off event". So I have to set the Scheduler -> Timer to 3600 seconds and hit "Change Expiration", then I can see that it's scheduled properly. Perhaps this stopped the homepage from refreshing?

    The wp_cache_gc is also not scheduled when upgrading the plugin from older versions (0.9.9) or switching from "Use mod_rewrite to serve cache files." to "Use PHP to serve cache files.". So we have to hit that "Change Expiration" button again. That means each time we tweaked some setting, the issue came back.

    What's most confusing is, that this is not indicated on the WP Super Cache options screen, so we were not aware of any of these issues. There is visible check of the garbage collector cron job.

    Thanks,
    Martin

    http://wordpress.org/extend/plugins/wp-super-cache/

  2. FolioVision
    Member
    Posted 1 year ago #

    Hello Donncha,

    please let us know what do you think about above.

    It appears that the plugin doesn't work properly without Garbage collector, so we think it should run all the time or be turned on by default.

    Or are we missing something else?

    Thanks,
    Martin

  3. Donncha O Caoimh
    Member
    Plugin Author

    Posted 1 year ago #

    Good points. The gc job is a single event because garbage collection could take longer than the period between scheduled events. That might cause the garbage collection to run twice in parallel without using flags to tell the second job to not run. Unfortunately if a job fails or times out then the flag may not be cleared and GC won't run at all until the system decides that the previous job had failed.

    Another way of doing it is by having a single event doing the garbage collection and using a scheduled job that checks if everything is running. This has it's own complications too.

    One issue with upgrading is that in the past the plugin would clear it's config files and clear up after itself. I've fixed this in the development version (but if you don't use the dev version the config will be cleared as usual when you next upgrade). Part of the clearing up is removing the gc job. It's not scheduled until you visit the settings page again :(

    The upgrading issue shouldn't be a problem after the next release.

  4. Biranit
    Member
    Posted 1 year ago #

    I have this issue with pretty much all major pages - categories, tags, author, etc. Anonymous users get served a week old page.

    I have the option for "cache rebuild" (serves anonymous users a cached page while building a new one) checked. It does not happen.

    For the homepage, I actually added a function to clear its cache whenever it is updated. I couldn't allow it to remain cached.

    I am now thinking that I will have no alternative but to write a function that clears out the cached file for every category/tag/author/taxonomy of a post when it is published/updated, which is quite cumbersome.

    But I have no idea how to solve this another way, and it is a rather acute problem.

    I would appreciate getting some guidance here.

    Thanks :)

    Bira

  5. Donncha O Caoimh
    Member
    Plugin Author

    Posted 1 year ago #

    Bira - try the development version or use the debug log in the plugin and examine the log. See if the paths in the logs are correct where the plugin records that it deletes cache files.

    http://ocaoimh.ie/y/2o

  6. FolioVision
    Member
    Posted 1 year ago #

    Hello Donncha,

    so can you make sure the garbage collector cron is scheduled in the next version? We are not sure if there should be an option to disable it at all.

    Hello Bira,

    we had similar issues - just check your WP Super Cache Advanced settings and see if there is a "Next scheduled garbage collection will be at" message below "Expiry Time & Garbage Collection". That will give you an idea if your Garbage collector is running.

    Thanks,
    Martin

  7. Biranit
    Member
    Posted 1 year ago #

    Hi Donncha, FolioVision,

    I am pretty sure there is a bug or a misconceived issue here. And I will try to explain myself better:

    1) I have 'preload' turned on for all posts. I do NOT have preload on for categories, tags, etc.

    2) I have garbage collection set to run every hour (3600 seconds) with timeout for files set to 600 seconds. It DOES state "next garbage collection <time>" on that page. However, it also states:

    "Warning! PRELOAD MODE activated. Supercache files will not be deleted regardless of age."

    3) So category or tag pages have now been older than one week - and I see absolutely no method or way to make them refresh for visitors. It is a major issue for us.

    So the way I see it, despite NOT having preload set for categories and other taxonomies, garbage collection actually does nothing because preload is turned on for everything else. And, also, there is just never ever a method by which pages are refreshed. Despite having "Cache rebuild. Serve a supercache file to anonymous users while a new file is being generated" checked - it just never does anything to refresh these pages.

    The only pages that are fresh are posts, which get rebuilt when they are published or updated; and pages (such as the homepage) where I manually added prune_super_cache() to their update function...

    I should point out all this began since the latest upgrade, a couple of weeks ago.

    Thanks,

    Bira

  8. Donncha O Caoimh
    Member
    Plugin Author

    Posted 1 year ago #

    Bira - is a page updated when a comment is made?

    The taxonomy pages like tags and categories should be updated each time you run a preload because at the end of the preload it deletes any stale pages. Can you enable debugging and run a preload? You should see this recorded in the log.

  9. Biranit
    Member
    Posted 1 year ago #

    Well preload only ran once, Donncha. Or, to be precise, it ran over something like 10 days before everything was cached. And I don't know if it's running now except when a new post is added?

    Right now, this is the state of our Cache Contents (just refreshed):

    WP-Cache (1.28MB)

    35 Cached Pages
    18 Expired Pages

    WP-Super-Cache (1,095.79MB)

    12160 Cached Pages
    0 Expired Pages

    The cached pages number increases daily, of course.

    As for comments: we use the Facebook comments plugin so I don't know.

    I added a function to sort out the categories issue to my functions.php - as things became rather urgent. My function is:

    function rgbtoi_prune_category_cache($post_id) {
    	if ( $post_id == null || empty($_POST) )
    		return;
    
    	if ( !isset( $_POST['post_type'] ) || $_POST['post_type']!='post' )
    		return; 
    
    	//verify post is not a revision
    	if ( !wp_is_post_revision( $post_id ) ) {
    		if (in_category(3, $post_id)) {
    			prune_super_cache( get_supercache_dir() . '/israel-and-the-region/', true );
    		}
    		if (in_category(4, $post_id)) {
    			prune_super_cache( get_supercache_dir() . '/jewish-times/', true );
    		}
    		if (in_category(5, $post_id)) {
    			prune_super_cache( get_supercache_dir() . '/israel-inside/', true );
    		}
    		if (in_category(6, $post_id)) {
    			prune_super_cache( get_supercache_dir() . '/ops-and-blogs/', true );
    		}
    		if (in_category(7, $post_id)) {
    			prune_super_cache( get_supercache_dir() . '/start-up-israel/', true );
    		}
    	}
    }
    add_action('save_post', 'rgbtoi_prune_category_cache', 15 );

    It's not ideal, but at least it solves my immediate problem with regards to categories - which was the most urgent issue.

    I will remove it over night when there is little traffic (we got a few breaking news stories with heavy traffic at the moment) and will run debugging to let you know what it says.

    Thank you very much for your assistance - I do appreciate it.

  10. Biranit
    Member
    Posted 1 year ago #

    Hi Donncha,

    I turned on debug for all IPs and clicked on run preload now. I don't see anything in the debug file about preload - and also pages that I access (anonymously, from a different browser) don't seem to show up in the debug.

    However, something very typical for category and tag pages is that it says for all of them something like this:

    10:14:59 /topic/us-troops-in-afghanistan/ No wp-cache file exists. Must generate a new one.
    10:14:59 /topic/us-troops-in-afghanistan/ In WP Cache Phase 2
    10:14:59 /topic/us-troops-in-afghanistan/ Setting up WordPress actions
    10:14:59 /topic/us-troops-in-afghanistan/ Created output buffer
    13:15:00 /topic/us-troops-in-afghanistan/ Output buffer callback
    13:15:00 /topic/us-troops-in-afghanistan/ Anonymous user detected. Only creating Supercache file.
    13:15:00 /topic/us-troops-in-afghanistan/ Gzipping buffer.
    13:15:00 /topic/us-troops-in-afghanistan/ Writing non-gzipped buffer to supercache file.
    13:15:00 /topic/us-troops-in-afghanistan/ Writing gzipped buffer to supercache file.
    13:15:00 /topic/us-troops-in-afghanistan/ Renamed temp supercache file to /home/toi/public_html/timesofisrael.com/wp-content/cache/supercache/www.timesofisrael.com/topic/us-troops-in-afghanistan/index.html
    13:15:00 /topic/us-troops-in-afghanistan/ Renamed temp supercache gz file to /home/toi/public_html/timesofisrael.com/wp-content/cache/supercache/www.timesofisrael.com/topic/us-troops-in-afghanistan/index.html.gz
    13:15:00 /topic/us-troops-in-afghanistan/ Writing gzip content headers. Sending buffer to browser
    13:15:00 /topic/us-troops-in-afghanistan/ wp_cache_shutdown_callback: collecting meta data.
    13:15:00 /topic/us-troops-in-afghanistan/ Did not write meta file: wp-cache-64883f325d9610a57494746fd1a6e21b.meta *1* *0* *1*

    This, despite the fact that the file DOES exist, and despite the fact that it keeps serving an old cached file. There is no error in the file path listed above.

    Does this help in any way?

    Thanks,

    Bira

  11. FolioVision
    Member
    Posted 1 year ago #

    Hello Donncha,

    I tested our issue of "Garbage Collector not being enabled after plugin install" in the most recent version from: http://ocaoimh.ie/the-development-version-of-wp-super-cache/

    It's still not working out of the box. So after the plugin is installed, and I go to Advanced settings, turn on Caching, set it to mod_rewrite, check "Don’t cache pages for known users" and "Mobile device support", then I hit "Update". Then I have to update the .htaccess as there is a big notice, so you can't forget that.

    But there is nothing about Garbage Collector. So it's one extra step which has to be observed. If you don't turn it on, then you might get into trouble. Perhaps it's not a problem for smaller sites, but for bigger sites it's a big problem.

    Thanks,
    Martin

  12. Donncha O Caoimh
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks Martin, I'll put in a check there and schedule the default garbage collection if it's not enabled.

  13. Donncha O Caoimh
    Member
    Plugin Author

    Posted 1 year ago #

    Martin - I've added code that will check if gc is scheduled or not when you activate the plugin. Unfortunately I bet it annoys other people who don't want to schedule a garbage collection! It's hard to account for every sort of install..

  14. FolioVision
    Member
    Posted 1 year ago #

    Hi Donncha,

    The issue is that pre version 1, WP Super Cache just worked.

    Now new installs and upgrades are fraught with danger, potentially leaving a server with all outdated files.

    The reason we recommended WP Super Cache over W3 Total Cache is how much less fussy WP Super Cache was.

    I wish you would go back to intelligent defaults with WP Super Cache. I.e. works out of the box. The tweaker/wankers will always prefer W3 Total Cache.

    Making the web work for you,
    Alec Kinnear
    Creative Director, Foliovision

  15. Biranit
    Member
    Posted 1 year ago #

    Hi Donncha,

    I would like to reiterate and add to FolioVision's post. Your plugin was to me one of the best WordPress plugins - I've recommended it to every WordPress-based website I've worked with, and installed it myself in dozens of websites I've been involved with, small or big.

    I now find myself having to write various functions to overcome a host of issues - not all yet solved for me - since upgrading the plugin. Preload is extremely buggy - I don't understand why, but it continues to delete itself and rebuild (even though that option is disabled), sending me dozens of error emails. Garbage collection most certainly does not work as it did - I wrote functions to sort out the issues it caused. And I am seriously shaking with fear in the thought of upgrading the next time there's a new version, because the impact of WPSC not working on a website with 1 million pageviews a day and over 10,000 articles can be detrimental.

    I remind myself all the time that this is a free plugin. Though I will pay for it if it were not. But I urge you, as Alec stated, to keep it working and keep it working out of the box. Please don't stray from its original simplicity and beauty.

    Many thanks,

    Bira

  16. Donncha O Caoimh
    Member
    Plugin Author

    Posted 1 year ago #

    FolioVision, Biranit - the plugin works out of the box for me and most people. I wouldn't ship something that I knew was broken but there are so many types of hosting that it's impossible to test every combination of plugins, operating system, Apache versions and whatever else.

    Have you tried going back to a version that works for you? If you're getting error messages, can you check the plugin for those error messages and attempt to figure out why it's not working? Send me a patch or even describe where in the code you think it's wrong. That would be really helpful.

    I have hardly any time to devote to this any more. One of the dangers of becoming a father I'm afraid.

  17. patecj
    Member
    Posted 1 year ago #

    Dont know why but my garbage collection is not at all working.

    It shows below message in advanced setting page.

    UTC time is 2012-08-31 17:32:51Local time is 2012-08-31 23:02:51
    Next scheduled garbage collection will be at 2012-08-31 17:32:32 UTC

    Also, I have enable email option whenever it runs but not getting any email for this.

    (I am using wp super cache for last 3 years, it works like charm but after my server upgrade last week, its not working.)

    Please help me to fix this.

    Is there any way we can set server cron job to run garbage collection?

  18. patecj
    Member
    Posted 1 year ago #

    When I check in cron view, its displaying as below.

    Aug 31, 2012 @ 17:32 (1346434352) One-off event wp_cache_gc

    I dont know what does it means?

  19. Biranit
    Member
    Posted 1 year ago #

    Hi Donncha,

    I just wanted to say I am really happy with the latest version. So far, everything - including preload (and we have 14,000 posts so far) - has gone smoothly, and it seems various bugs have been fixed. So many thanks for a great job done.

    I would like to make a suggestion, however, perhaps for future versions.

    Add a few options for what happens when a post is published:

    When a post is published:

    - Check box to clear homepage chace
    - Check box to clear author page cache
    - Check box to clear related (and only related) taxonomy (category/tags/custom taxonomy) cache

    I already added functions to my functions.php that do this on save_post, but I reckon this is important - especially for folks like me who use preload.

    Many thanks again,

    Bira

  20. Donncha O Caoimh
    Member
    Plugin Author

    Posted 1 year ago #

    @Biranit - any chance you could send me a patch adding that code to the plugin? It'll also need a settings page with those checkboxes of course.

  21. eshimoda
    Member
    Posted 1 year ago #

    @Biranit You have just saved my life that your temporary solution suited me perfectly.

  22. Madd1974
    Member
    Posted 1 year ago #

    @Biranit
    I would like to clear the homepage-cache, when a new post is published.
    Can you please send me the code, that you use in your functions.php? It would be nice.

  23. Biranit
    Member
    Posted 1 year ago #

    Hi Madd1974,

    I don't actually use a specific function for the homepage -- I did try in the past to use do_action( 'gc_cache', 'prune', 'homepage' ); -- but that did not seem to work for me.

    So instead, I have something more explicit -- probably a not the shortest version possible, but it works...

    Put this function in your theme's functions.php -- it will delete the cached homepage on every published post save (that is, if you publish a post and/or update a published post). Feel free to change as needed:

    function prune_wpsc_homepage_on_post_save ($post_id) {
    
    	if ( $post_id == null || empty($_POST) )
    		return;
    
    	// remove these next two lines of code if you want the hp to
    	//  be deleted on save_post of other post types than regular posts
    	if ( !isset( $_POST['post_type'] ) || $_POST['post_type']!='post' )
    		return;
    
    	if ( !wp_is_post_revision( $post_id ) ) {
    		// explicitly removes all versions of the homepage - compressed and mobile
    		prune_super_cache( get_supercache_dir() . '/index.html', true );
    		prune_super_cache( get_supercache_dir() . '/index.html.gz', true );
    		prune_super_cache( get_supercache_dir() . '/index-mobile.html', true );
    		prune_super_cache( get_supercache_dir() . '/index-mobile.html.gz', true );
    	}
    
    }
    add_action('save_post', 'prune_wpsc_homepage_on_post_save', 15 );

    Let me know if you have any questions.

    Cheers,

    Bira

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic