Title: Adding non persistent groups doesn&#8217;t always work
Last modified: March 9, 2018

---

# Adding non persistent groups doesn’t always work

 *  [martin.krcho](https://wordpress.org/support/users/martinkrcho/)
 * (@martinkrcho)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/adding-non-persistent-groups-doesnt-always-work/)
 * I think I found an issue with your code that handles non persistent groups.
 * I need to prevent Redis from caching “alloptions” value, so I call the following
   code as early as possible (muplugins_loaded hook).
 *     ```
       wp_cache_add_non_persistent_groups( array(
       	'options',
       	'main_site-options'
       ) );
       ```
   
 * Despite this, the “alloptions” value still comes from the internal $cache array
   in the WP_Object_Cache object in your plugin.
 * This is happening because the get function in WP_Object_Cache object first checks
   internal $cache and then checks whether it should be persisted.
 * I believe there are 2 possible fixes:
    * change logic in WP_Object_Cache::get
   to check if the group is persistent before trying to retrieve it from internal
   cache * change function WP_Object_Cache::add_non_persistent_groups to delete 
   all already cached values that belong to one of the groups being added

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [martin.krcho](https://wordpress.org/support/users/martinkrcho/)
 * (@martinkrcho)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/adding-non-persistent-groups-doesnt-always-work/#post-10056467)
 * Here’s suggested patch for the function `WP_Object_Cache::add_non_persistent_groups`:
 *     ```
       public function add_non_persistent_groups( $groups ) {
   
       	$groups = (array) $groups;
   
       	$groups = array_fill_keys( $groups, true );
       	$this->non_persistent_groups = array_merge( $this->non_persistent_groups, $groups );
   
       	foreach (array_keys($groups) as $group) {
   
       		foreach ($this->cache as $cacheKey => $cacheValue) {
   
       			$pattern = '/^'.WP_CACHE_KEY_SALT.$group.':/';
       			if (preg_match($pattern, $cacheKey)) {
       				unset($this->cache[$cacheKey]);
       			}
   
       		}
   
       	}
   
       }
       ```
   
 *  Plugin Contributor [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * (@danielbachhuber)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/adding-non-persistent-groups-doesnt-always-work/#post-10071294)
 * Hi [@martinkrcho](https://wordpress.org/support/users/martinkrcho/),
 * Thanks for the report.
 * > I need to prevent Redis from caching “alloptions” value, so I call the following
   > code as early as possible (muplugins_loaded hook).
 * Can you explain why you want to prevent Redis from caching ‘alloptions’?
 * The `muplugins_loaded` hook is likely too late to use `wp_cache_add_non_persistent_groups()`,
   as options will already have been loaded by that point.
 * > Here’s suggested patch for the function
 * You’re welcome to use this in a fork of the plugin. I’m not sure it makes sense
   to include in the main plugin as it will cause the plugin’s behavior to deviate
   from WordPress core.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding non persistent groups doesn’t always work’ is closed to new replies.

 * ![](https://ps.w.org/wp-redis/assets/icon-256x256.png?rev=3417699)
 * [WP Redis](https://wordpress.org/plugins/wp-redis/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-redis/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-redis/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-redis/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-redis/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-redis/reviews/)

## Tags

 * [cache](https://wordpress.org/support/topic-tag/cache/)

 * 2 replies
 * 2 participants
 * Last reply from: [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/adding-non-persistent-groups-doesnt-always-work/#post-10071294)
 * Status: not resolved