Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author petermolnar

    (@cadeyrn)

    You don’t need WP to do that, just

    * * * * * user_xyz echo 'flush_all' | netcat localhost 11211

    More examples:
    https://www.cyberciti.biz/faq/linux-unix-flush-contents-of-memcached-instance/

    Thread Starter Harry Milatz

    (@harry-milatz)

    Hi Peter,

    yes i could do this but i want to flush the cache with the same cronjob with which one i empty the autoptimize cache, because in the memcached cache are not existing .css and .js files and for that moment the site is “broken” until i flush the cache manually;)
    So in this case i want to WP do that.

    This is the code for the Cronjob:

    if ( !wp_next_scheduled('autopt_cache') ) {
    	wp_schedule_event( time(), 'weekly', 'autopt_cache' );
    }
    
    add_action('autopt_cache', 'autopt_cache_function');
    function autopt_cache_function() {
    	foreach (array("","js","css") as $scandirName) {
    		$scan[$scandirName] = scandir(WP_CONTENT_DIR.'/cache/autoptimize/'.$scandirName);
    	}
    
    	foreach ($scan as $scandirName=>$scanneddir) {
    		$thisAoCacheDir=rtrim(WP_CONTENT_DIR.'/cache/autoptimize/'.$scandirName,"/")."/";
    		foreach($scanneddir as $file) {
    			if(!in_array($file,array('.','..')) && strpos($file,'autoptimize_') !== false && is_file($thisAoCacheDir.$file)) {
    				@unlink($thisAoCacheDir.$file);
    			}
    		}
    	}
    	@unlink(WP_CONTENT_DIR.'/cache/autoptimize/'."/.htaccess");
    //here i want to flush the memcached cache
    }

    Best regards,
    Harry

    Plugin Author petermolnar

    (@cadeyrn)

    Ah, you’re referring to WP Cron.
    You said cron, that is system cron for me.

    It’s not as obvious as it sounds; in theory you either have a global $wp_ffpc, which is an object, or do a new WP_FFPC, but that requires the defaults to be passed. The global $wp_ffpc; should do it.

    Once you have this, call
    $wp_ffpc->backend->clear($p1, $p2);

    $p1 is an optional post ID
    $p2 is optional force, so

    $wp_ffpc->backend->clear(null, false);
    will trigger the set method, while

    $wp_ffpc->backend->clear(null, true);
    will always trigger a full cache flush.

    If it doesn’t work, please get back to me.

    Thread Starter Harry Milatz

    (@harry-milatz)

    Ah ok, sorry;)
    This

    if ( !wp_next_scheduled('autopt_cache') ) {
    	wp_schedule_event( time(), 'weekly', 'autopt_cache' );
    }
    
    add_action('autopt_cache', 'autopt_cache_function');
    function autopt_cache_function() {
    	foreach (array("","js","css") as $scandirName) {
    		$scan[$scandirName] = scandir(WP_CONTENT_DIR.'/cache/autoptimize/'.$scandirName);
    	}
    
    	foreach ($scan as $scandirName=>$scanneddir) {
    		$thisAoCacheDir=rtrim(WP_CONTENT_DIR.'/cache/autoptimize/'.$scandirName,"/")."/";
    		foreach($scanneddir as $file) {
    			if(!in_array($file,array('.','..')) && strpos($file,'autoptimize_') !== false && is_file($thisAoCacheDir.$file)) {
    				@unlink($thisAoCacheDir.$file);
    			}
    		}
    	}
    	@unlink(WP_CONTENT_DIR.'/cache/autoptimize/'."/.htaccess");
    global $wp_ffpc;
    $wp_ffpc->backend->clear(null, true);
    }

    doesn’t work for now.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘flushing cache via cronjob’ is closed to new replies.