php 强制清除过期的WP Super Cache文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 强制清除过期的WP Super Cache文件相关的知识,希望对你有一定的参考价值。

<?php
/**
 * Plugin Name: RT Force Cache Refresh
 * Plugin URI: http://www.this-play.nl
 * Description: Periodically deletes expired WP Super Cache files using WP-Cron
 * Version: 0.8
 * Author: Roy Tanck
 * Author URI: http://www.this-play.nl
 * License: GPL2
 */

/**
 * On activation, add scheduled event, but only on main site
 */
if( !function_exists('rt_force_cache_refresh_activation')){

	function rt_force_cache_refresh_activation() {
		if ( is_main_site() && !wp_next_scheduled( 'rt_cache_refresh_event' ) ) {
			wp_schedule_event( time(), 'rt_cache_refresh', 'rt_cache_refresh_event');
		}
	}

	register_activation_hook( __FILE__, 'rt_force_cache_refresh_activation' );

}


/**
 * On deactivation, remove all functions from the scheduled action hook.
 */
if( !function_exists('rt_force_cache_refresh_deactivation')){

	function rt_force_cache_refresh_deactivation() {
		wp_clear_scheduled_hook( 'rt_cache_refresh_event' );
	}

	register_deactivation_hook( __FILE__, 'rt_force_cache_refresh_deactivation' );

}


/**
 * Attempt to delete expired cache files by calling a WPSC function directly
 */
if( !function_exists('rt_cache_refresh_delete_expired')){

	function rt_cache_refresh_delete_expired() {
		global $file_prefix;
		if( function_exists('wp_cache_clean_expired') && isset( $file_prefix ) ){
			wp_cache_clean_expired($file_prefix);
			error_log( 'RT Force Cache Refresh: Super Cache cleaned' );
		} else {
			error_log( 'RT Force Cache Refresh: Super Cache clean failed, prefix: ' . $file_prefix );
		}
	}

	// if the event fires, call the delete function
	add_action( 'rt_cache_refresh_event', 'rt_cache_refresh_delete_expired' );

}


/**
 * Function to add a custom cron recurrence for the cleanup
  */
if( !function_exists('rt_add_cache_refresh_recurrence')){

	function rt_add_cache_refresh_recurrence( $schedules ) {
		// Add to the existing schedules
		$schedules['rt_cache_refresh'] = array(
			'interval' => 900,
			'display' => __( 'RT Cache Refresh' )
		);
		return $schedules;
	}

	add_filter( 'cron_schedules', 'rt_add_cache_refresh_recurrence' );
}

?>

以上是关于php 强制清除过期的WP Super Cache文件的主要内容,如果未能解决你的问题,请参考以下文章

php 保存任何帖子时清除一些WP Super Cache文件

最佳 WordPress 静态缓存插件 WP Super Cache 安装和使用(转)

apache_conf WordPress .htaccess配置文件。允许强制SSL,隐藏wp-config.php,标头ETag,GZIP压缩和过期缓存。

apache_conf WP Super Cache .htaccess

WP Super Cache缓存插件优化设置过程

如何安装WP Super Cache加速WordPress网站访问速度