You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The object-cache.php in the Memcached Object Cache does not currently support the wp_suspend_cache_addition() function, unlike the core WordPress object cache implementation in class-wp-object-cache.php. This can lead to memory exhaustion in certain scenarios due to uncontrolled local caching ($wp_object_cache->cache).
I propose implementing this function in object-cache.php to align its functionality with the core object cache class to offer more flexibility in utilizing limited memory effectively.
Context:
In the WordPress core object cache implementation (class-wp-object-cache.php), the method add() includes a check for wp_suspend_cache_addition(). This allows developers to prevent local caching under certain conditions.
public function add( $key, $data, $group = 'default', $expire = 0 ) {
if ( wp_suspend_cache_addition() ) {
return false;
}
// Rest of the code...
}
However, in object-cache.php, there is no similar mechanism. While object-cache.php has a distinctive feature called no_mc_groups, this prevents data from being stored in Memcache but does not prevent it from being stored in the local cache.
Problems:
Without the ability to suspend local cache addition, unnecessary accumulation can occur in scenarios like sitemap generation, backups or other large-scale processes involving a massive volume of queries that are not reused.
Developers lack control over whether data is stored in the local cache, potentially leading to unnecessary memory usage, which can ultimately result in PHP memory exhaustion, triggering a Fatal error and causing processes to halt.
Proposal:
I propose implementing support for wp_suspend_cache_addition() in object-cache.php, similar to how it is implemented in the core object cache class. This would give developers the ability to prevent local caching when necessary.
function add( $id, $data, $group = 'default', $expire = 0 ) {
// Check if cache addition is suspended
if ( wp_suspend_cache_addition() ) {
return false;
}
$key = $this->key( $id, $group );
if ( is_object( $data ) ) {
$data = clone $data;
}
if ( in_array( $group, $this->no_mc_groups ) ) {
if ( ! isset( $this->cache[ $key ] ) ) {
$this->cache[ $key ] = [
'value' => $data,
'found' => false,
];
return true;
}
return false;
}
// Rest of the code...
}
Conclusion:
Implementing support for wp_suspend_cache_addition() in object-cache.php will align it with the WordPress core object cache class and provide a more flexible and memory-efficient caching solution for developers. This will help mitigate issues related to unnecessary memory usage and PHP memory exhaustion, ultimately improving the reliability of resource-heavy processes.
That said, the issue of unnecessary local cache accumulation can be avoided if plugins that provide features like sitemap generation (e.g., Jetpack) choose to bypass cache-heavy functions like get_posts or get_post_meta and instead directly execute SQL queries using $wpdb. However, this is a separate issue that should be addressed at the plugin level. I believe it is still crucial for object-cache.php to support wp_suspend_cache_addition(), as it would allow developers to have greater control over local cache behavior. It's also worth noting that a simple search for "Allowed memory size exhausted" related to object-cache.php brings up numerous unresolved discussions on forums and support channels. This highlights how common and significant this issue is for developers working with resource-heavy WordPress sites.
Thank you for considering this enhancement. I believe that implementing wp_suspend_cache_addition() in object-cache.php will provide developers with more flexibility and help improve PHP memory management in high-demand scenarios.
The text was updated successfully, but these errors were encountered:
Summary:
The
object-cache.php
in the Memcached Object Cache does not currently support thewp_suspend_cache_addition()
function, unlike the core WordPress object cache implementation inclass-wp-object-cache.php
. This can lead to memory exhaustion in certain scenarios due to uncontrolled local caching ($wp_object_cache->cache
).wp_suspend_cache_addition() - WordPress Developer Resources
I propose implementing this function in
object-cache.php
to align its functionality with the core object cache class to offer more flexibility in utilizing limited memory effectively.Context:
In the WordPress core object cache implementation (
class-wp-object-cache.php
), the methodadd()
includes a check forwp_suspend_cache_addition()
. This allows developers to prevent local caching under certain conditions.WordPress/wp-includes/class-wp-object-cache.php - GitHub
However, in
object-cache.php
, there is no similar mechanism. Whileobject-cache.php
has a distinctive feature calledno_mc_groups
, this prevents data from being stored in Memcache but does not prevent it from being stored in the local cache.Problems:
Proposal:
I propose implementing support for
wp_suspend_cache_addition()
inobject-cache.php
, similar to how it is implemented in the core object cache class. This would give developers the ability to prevent local caching when necessary.For example, the add() method in object-cache.php could be updated as follows:
Conclusion:
Implementing support for
wp_suspend_cache_addition()
inobject-cache.php
will align it with the WordPress core object cache class and provide a more flexible and memory-efficient caching solution for developers. This will help mitigate issues related to unnecessary memory usage and PHP memory exhaustion, ultimately improving the reliability of resource-heavy processes.That said, the issue of unnecessary local cache accumulation can be avoided if plugins that provide features like sitemap generation (e.g., Jetpack) choose to bypass cache-heavy functions like
get_posts
orget_post_meta
and instead directly execute SQL queries using$wpdb
. However, this is a separate issue that should be addressed at the plugin level. I believe it is still crucial forobject-cache.php
to supportwp_suspend_cache_addition()
, as it would allow developers to have greater control over local cache behavior. It's also worth noting that a simple search for "Allowed memory size exhausted" related toobject-cache.php
brings up numerous unresolved discussions on forums and support channels. This highlights how common and significant this issue is for developers working with resource-heavy WordPress sites.Thank you for considering this enhancement. I believe that implementing
wp_suspend_cache_addition()
inobject-cache.php
will provide developers with more flexibility and help improve PHP memory management in high-demand scenarios.The text was updated successfully, but these errors were encountered: