Opened 9 months ago
Last modified 6 months ago
#63022 new enhancement
Update cache.php - Improve function wp_cache_decr
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Cache API | Keywords: | has-patch close |
| Focuses: | performance | Cc: |
Description
Make the lines 519-549 in class-wp-object-cache.php obsolete by adjusting the function call to the function wp_cache_decr, line 252 in cache.php.
Change
return $wp_object_cache->decr( $key, $offset, $group );
to
return $wp_object_cache->incr( $key, ((int) $offset) * -1), $group );
because DECR by offset == INCR by (offset * -1)
Change History (5)
This ticket was mentioned in PR #8413 on WordPress/wordpress-develop by @docjojo.
9 months ago
#1
- Keywords has-patch added
#2
in reply to:
↑ description
@
9 months ago
Replying to docjojo:
Make the lines 519-549 in class-wp-object-cache.php obsolete by adjusting the function call to the function wp_cache_decr, line 252 in cache.php.
Change
return $wp_object_cache->decr( $key, $offset, $group );
to
return $wp_object_cache->incr( $key, ((int) $offset) * -1), $group );
because DECR by offset == INCR by (offset * -1)
i have the same problem
.................
return $wp_object_cache->decr( $key, $offset, $group );
to
return $wp_object_cache->incr( $key, ((int) $offset) * -1), $group );
#3
follow-up:
↓ 5
@
8 months ago
- Keywords close added; wp_cache_decr removed
- Version 6.7.2 deleted
@docjojo Thank you for raising this.
Can you share some context on why this is useful? Given that there is already a decr() method required on the object class implementation, I don't see a benefit of not using it.
Now if we were to rearchitect this from scratch, I could see it being useful to avoid the method. But not using it when we have it does not seem useful to me. It would only make sense to me if we planned to deprecate this method and no longer require it on the object cache implementation. But I'm not sure it's worth the change. Thoughts @tillkruess?
#5
in reply to:
↑ 3
@
8 months ago
It’s not about removing the functionality — it’s about reducing code duplication.
The idea is to let decr() simply delegate to incr() with a negative offset:
return $wp_object_cache->incr( $key, ((int) $offset) * -1), $group );
This allows decr() to be removed entirely (30 lines gone), with no functional side effects and no additional function calls — just a bit of math.
Fewer lines to maintain, less to compile, and cleaner internal logic.
C.
Replying to flixos90:
@docjojo Thank you for raising this.
Can you share some context on why this is useful? Given that there is already a
decr()method required on the object class implementation, I don't see a benefit of not using it.
Now if we were to rearchitect this from scratch, I could see it being useful to avoid the method. But not using it when we have it does not seem useful to me. It would only make sense to me if we planned to deprecate this method and no longer require it on the object cache implementation. But I'm not sure it's worth the change. Thoughts @tillkruess?
Make the lines 519-549 in class-wp-object-cache.php obsolete by adjusting the function call to the function wp_cache_decr, line 252 in cache.php.
Change
return $wp_object_cache->decr( $key, $offset, $group );to
return $wp_object_cache->incr( $key, ((int) $offset) * -1), $group );because DECR by offset == INCR by (offset * -1)
Trac ticket:
https://core.trac.wordpress.org/ticket/63022#ticket