Introduce wp_suspend_cache_addition() to allow reduced memory usage when cache additions aren't useful. Fixes #5389.

git-svn-id: http://svn.automattic.com/wordpress/trunk@18681 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
duck_ 2011-09-15 20:23:00 +00:00
parent a96e0dff91
commit cda68f14f9
2 changed files with 27 additions and 0 deletions

View File

@ -294,6 +294,9 @@ class WP_Object_Cache {
* @return bool False if cache key and group already exist, true on success * @return bool False if cache key and group already exist, true on success
*/ */
function add( $key, $data, $group = 'default', $expire = '' ) { function add( $key, $data, $group = 'default', $expire = '' ) {
if ( wp_suspend_cache_addition() )
return false;
if ( empty ($group) ) if ( empty ($group) )
$group = 'default'; $group = 'default';

View File

@ -3709,6 +3709,30 @@ function wp_guess_url() {
return rtrim($url, '/'); return rtrim($url, '/');
} }
/**
* Temporarily suspend cache additions.
*
* Stops more data being added to the cache, but still allows cache retrieval.
* This is useful for actions, such as imports, when a lot of data would otherwise
* be almost uselessly added to the cache.
*
* Suspension lasts for a single page load at most. Remember to call this
* function again if you wish to re-enable cache adds earlier.
*
* @since 3.3.0
*
* @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
* @return bool The current suspend setting
*/
function wp_suspend_cache_addition( $suspend = null ) {
static $_suspend = false;
if ( is_bool( $suspend ) )
$_suspend = $suspend;
return $_suspend;
}
/** /**
* Suspend cache invalidation. * Suspend cache invalidation.
* *