-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 58f86ad
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |