Make WordPress Core

Changeset 52772


Ignore:
Timestamp:
02/18/2022 12:04:52 PM (2 years ago)
Author:
spacedmonkey
Message:

Cache API: Add wp_cache_flush_runtime function

Add a new function called wp_cache_flush_runtime to existing caching functions found in WordPress. This function allows users to flush the runtime (in-memory) cache, without flushing the entire persistent cache.

Props: Spacedmonkey, tillkruess, flixos90, adamsilverstein, SergeyBiryukov, barryhughes.
Fixes: #55080.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/cache-compat.php

    r52708 r52772  
    124124    }
    125125endif;
     126
     127if ( ! function_exists( 'wp_cache_flush_runtime' ) ) :
     128    /**
     129     * Removes all cache items from the in-memory runtime cache.
     130     *
     131     * Compat function to mimic wp_cache_flush_runtime().
     132     *
     133     * @ignore
     134     * @since 6.0.0
     135     *
     136     * @see wp_cache_flush_runtime()
     137     *
     138     * @return bool True on success, false on failure.
     139     */
     140    function wp_cache_flush_runtime() {
     141        return wp_using_ext_object_cache() ? false : wp_cache_flush();
     142    }
     143endif;
  • trunk/src/wp-includes/cache.php

    r52708 r52772  
    270270
    271271/**
     272 * Removes all cache items from the in-memory runtime cache.
     273 *
     274 * @since 6.0.0
     275 *
     276 * @see WP_Object_Cache::flush()
     277 *
     278 * @return bool True on success, false on failure.
     279 */
     280function wp_cache_flush_runtime() {
     281    return wp_cache_flush();
     282}
     283
     284/**
    272285 * Closes the cache.
    273286 *
  • trunk/tests/phpunit/tests/pluggable.php

    r52706 r52772  
    327327                    ),
    328328                    'wp_cache_flush'                     => array(),
     329                    'wp_cache_flush_runtime'             => array(),
    329330                    'wp_cache_close'                     => array(),
    330331                    'wp_cache_add_global_groups'         => array( 'groups' ),
Note: See TracChangeset for help on using the changeset viewer.