You don’t need WP to do that, just
* * * * * user_xyz echo 'flush_all' | netcat localhost 11211
More examples:
http://www.cyberciti.biz/faq/linux-unix-flush-contents-of-memcached-instance/
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
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.
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.