Title: The wp_cache_incr() function doesn&#8217;t work as expected
Last modified: February 15, 2017

---

# The wp_cache_incr() function doesn’t work as expected

 *  Resolved [gioni](https://wordpress.org/support/users/gioni/)
 * (@gioni)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/the-wp_cache_incr-function-doesnt-work-as-expected/)
 * Hi Daniel!
 * I’ve got the problem. The function always returns false when the plugin is active(
   the file is in the wp-content folder).

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

 *  Plugin Contributor [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * (@danielbachhuber)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/the-wp_cache_incr-function-doesnt-work-as-expected/#post-8807559)
 * Can you share steps to reproduce, please?
 * And, just to confirm, the cache key you’re trying to increment already exists?`
   wp_cache_incr()` requires the key to already exist with a value:
 *     ```
       public function incr( $key, $offset = 1, $group = 'default' ) {
       	if ( empty( $group ) )
       		$group = 'default';
   
       	if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
       		$key = $this->blog_prefix . $key;
   
       	if ( ! $this->_exists( $key, $group ) )
       		return false;
       ```
   
 *  Thread Starter [gioni](https://wordpress.org/support/users/gioni/)
 * (@gioni)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/the-wp_cache_incr-function-doesnt-work-as-expected/#post-8808264)
 * Thanks, I’ll try the code you’ve suggested.
 * To be exact I’m trying to get the plugin working together with Batcache [https://wordpress.org/plugins/batcache/](https://wordpress.org/plugins/batcache/).
   Batcache uses object cache to store rendered pages. To clear the cache it uses
   the following code
 *     ```
       $url_key = md5( $url );
       wp_cache_add("{$url_key}_version", 0, $batcache->group);
       $retval = wp_cache_incr("{$url_key}_version", 1, $batcache->group);
       ```
   
 * It seems that code is not working now because I’m unable to clear the cache this
   way.
 *  Plugin Contributor [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * (@danielbachhuber)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/the-wp_cache_incr-function-doesnt-work-as-expected/#post-8814745)
 * That’s odd.
 * Can you debug a bit further into the object cache code to see where specifically
   it might be failing?
 *  Thread Starter [gioni](https://wordpress.org/support/users/gioni/)
 * (@gioni)
 * [8 years, 12 months ago](https://wordpress.org/support/topic/the-wp_cache_incr-function-doesnt-work-as-expected/#post-9190902)
 * Hi, Daniel!
 * It seems that it’s solved. There was an issue with default REDIS configuration.
   Sometimes REDIS wrote to the log: “Can’t save in background: fork: Cannot allocate
   memory”. After I had allowed overcommitting memory the issue was gone.
 * Just in case:
 * 1. Add vm.overcommit_memory = 1 to /etc/sysctl.conf
    2. Run the command sysctl
   vm.overcommit_memory=1
 *  Plugin Contributor [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * (@danielbachhuber)
 * [8 years, 12 months ago](https://wordpress.org/support/topic/the-wp_cache_incr-function-doesnt-work-as-expected/#post-9190967)
 * Glad you were able to sort it out, [@gioni](https://wordpress.org/support/users/gioni/).
   When in doubt, always check the logs 🙂

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

The topic ‘The wp_cache_incr() function doesn’t work as expected’ 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/)

 * 5 replies
 * 2 participants
 * Last reply from: [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * Last activity: [8 years, 12 months ago](https://wordpress.org/support/topic/the-wp_cache_incr-function-doesnt-work-as-expected/#post-9190967)
 * Status: resolved