Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
emaildano committed Mar 9, 2018
0 parents commit 58f86ad
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions redis-cache-fix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/*
Plugin Name: Redis Object Cache fix
Plugin URI:
Description:
Version: 0.1
Author: DigitalCube
Author URI: https://www.digitalcube.jp/
License: GPLv2 or later
*/

class redis_cache_fix {
public function __construct() {
add_action( 'add_option', array( $this, 'option_cache_flush' ) );
add_action( 'update_option', array( $this, 'option_cache_flush' ) );
add_action( 'delete_option', array( $this, 'option_cache_flush' ) );
}

// update_option, delete_option 時に cache をフラッシュ
public function option_cache_flush($option, $old_value = '', $value = ''){
if ( !empty( $option ) ) {
wp_cache_delete( $option, 'options' );
foreach (array('alloptions','notoptions') as $options_name) {
$options = wp_cache_get( $options_name, 'options' );
if ( ! is_array($options) ) {
$options = array();
}
if ( isset($options[$option]) ) {
unset($options[$option]);
wp_cache_set( $options_name, $options, 'options' );
}
unset($options);
}
}
return;
}
};
new redis_cache_fix();

0 comments on commit 58f86ad

Please sign in to comment.