Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support Torsten Landsiedel

    (@zodiac1978)

    Why do you want to do that? You shouldn’t delete the complete cache without a reason. Of course you can just delete all the cache files, but this just works if you have used the HDD method.

    You can use the WordPress cron in this way to flush the whole cache:

    if ( ! wp_next_scheduled( 'my_cachify_flush_cache' ) ) {
        wp_schedule_event( time(), 'twicedaily', 'my_cachify_flush_cache' );
    }
    
    add_action( 'my_cachify_flush_cache', array( 'Cachify', 'flush_total_cache' ) );

    Maybe you can work something out with this starting point.

    All the best,
    Torsten

    Thread Starter vojtechm

    (@vojtechm)

    Hi,

    thank you for info. All I need is to remove cache files (or flush cache), like you said, once a day after midnight. I use HDD method but I don’t how to do so. Is there any script for it?

    I can’t get your script working. Where shall I put it?

    Thank you very much.
    Br, Vojta

    I’m interested in that topic as well. I tried out this solution https://ww.wp.xz.cn/support/topic/flush-cache-and-rebuild?replies=3 but it doesn’t work.
    My questions are:

    Is this the right way to flush and rebuild the cache via Cron for db storage, or is this the solution for hdd caching?

    My page is hosted under a shared host, so i don’t have the possibility to look up server logs. Is there another way to debug a cron job script?

    My intention to flush and rebuild the cache is cause my RSS feed won’t be updated in the cached version. So i thought rebuilding the cache once an hour is a good solution. If there is another one (for example to exclude parts of a website) please post it here.

    Thanks in advance
    Mupa

    No ideas?

    Plugin Support Torsten Landsiedel

    (@zodiac1978)

    I can’t get your script working. Where shall I put it?

    You can make a functionality plugin out of it:
    https://gist.github.com/Zodiac1978/1d9f33ef1be377869ad3

    Or you can put this code in your functions.phpof your (child) theme. But you should know, that an update of the theme maybe overwrites your addition.

    You can find valid values here:
    https://codex.ww.wp.xz.cn/Function_Reference/wp_schedule_event
    (so I think you want to use “daily”)

    My intention to flush and rebuild the cache is cause my RSS feed won’t be updated in the cached version. So i thought rebuilding the cache once an hour is a good solution. If there is another one (for example to exclude parts of a website) please post it here.

    A cache which is deleted before it is really used seems to be not very useful IMHO.

    I’ve opened up a Github issue for our developers, maybe they can help:
    https://github.com/pluginkollektiv/cachify/issues/26

    All the best,
    Torsten

    By the way, with RSS feed i don’t mean the feed of my own site. I’m using the RSS reader widget which comes with WordPress to show the last 10 headlines of a specific RSS feed.
    So i have a small box on the right side of all my sub sites which shows the last 10 headlines of for example http://www.sport1.de/tennis/news.rss.

    Plugin Support Torsten Landsiedel

    (@zodiac1978)

    This sort of dynamic content inside the page cannot be excluded from Cachify, but if you delete the cache every hour the caching doesn’t make any sense anymore, I think …

    All the best,
    Torsten

    I have found a solution for this use case:
    If you have RSS content which needs to be updated frequently, then don’t let WordPress do the job. I now have created a RSS widget (there are tons of generators) and pasted it into the text widget from WordPress. The generated RSS widget has some javascript which does the update job itself. So now it doesn’t matter if the code is compressed or not.

    Plugin Support Torsten Landsiedel

    (@zodiac1978)

    This looks like a great solution for this use case. Thanks for sharing!

    All the best,
    Torsten

    Thread Starter vojtechm

    (@vojtechm)

    Hi,

    sorry to bother again but this script really do nothing after few days of testing. I’ve put it into my functions.php (all scripts from it works ok). What did I do wrong? This is the code I’ve put into end of functions.php file of my theme.

    if ( ! wp_next_scheduled( 'my_cachify_flush_cache' ) ) {
        wp_schedule_event( time(), 'daily', 'my_cachify_flush_cache' );
    }
    
    add_action( 'my_cachify_flush_cache', array( 'Cachify', 'flush_total_cache' ) );

    It really drives me mad since I need to get this done.

    Could you please check if script works properly?

    Thank you.
    Br, Vojta

    Hey there

    I just tested this snippet using the WP Crontrol plugin. When I put the snippet into the functions.php file of the theme, the cron hook gets successfully registered, and when the action is being run, Cachify::flush_total_cache() is called as expected.

    I recommend you to test it using WP Crontrol as well, as this plugin will show you when the cron job ran for the last time and allows you to run it manually as well. It could certainly be possible that cron itself isn’t working on your site, which this plugin will tell you.

    NB: If you want to flush the cache of all caching methods (DB, Memcached, APC) and no just the current method (which should suffice, but you never know), you can also use this:

    if ( ! wp_next_scheduled( 'my_cachify_flush_cache' ) ) {
    	wp_schedule_event( time(), 'daily', 'my_cachify_flush_cache' );
    }
    function my_cachify_flush_cache() {
    	if ( class_exists( 'Cachify' ) ) {
    		Cachify::flush_total_cache( true );
    	}
    }
    add_action( 'my_cachify_flush_cache', 'my_cachify_flush_cache' );

    Again, this works like a charm on my local site running 4.5.

    Thread Starter vojtechm

    (@vojtechm)

    Hi,

    this solved my issue!!! Thank you very much for your help πŸ™‚

    Br, Vojta

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘CRON cache flush’ is closed to new replies.