Created
December 22, 2017 03:28
-
-
Save wokamoto/5c0c8a19a6dbd08e4121aa05d238543c to your computer and use it in GitHub Desktop.
[WordPress] Redis Object Cache プラグインとか導入するとキャッシュがきつすぎてオプションが保存されない時あるよね ref: https://qiita.com/wokamoto/items/3498bb74d492258585f7
This file contains hidden or 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
<?php | |
wp_cache_delete ( 'alloptions', 'options' ); | |
?> |
This file contains hidden or 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
<?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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment