Make WordPress Core


Ignore:
Timestamp:
10/10/2022 06:20:28 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Cache API: Introduce wp_cache_supports() function.

WordPress has recently introduced a variety of caching API improvements:

  • wp_cache_add_multiple()
  • wp_cache_set_multiple()
  • wp_cache_get_multiple()
  • wp_cache_delete_multiple()
  • wp_cache_flush_runtime()
  • wp_cache_flush_group()

Although WordPress core provides a compatibility layer if these functions are missing from third-party object cache implementations, there should be a method of checking whether the cache backend supports a particular feature.

This commit aims to improve developer experience by allowing third-party object cache plugins to declare a wp_cache_supports() function and correctly list their supported features:

  • add_multiple
  • set_multiple
  • get_multiple
  • delete_multiple
  • flush_runtime
  • flush_group

Note: The wp_cache_supports() function replaces and supersedes the wp_cache_supports_group_flush() function added earlier.

Follow-up to [47938], [47944], [52700], [52703], [52706], [52708], [53763], [53767], [54423].

Props johnjamesjacoby, tillkruess, spacedmonkey, SergeyBiryukov.
Fixes #56605.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/object-cache.php

    r54423 r54448  
    314314
    315315/**
    316  * Whether the object cache implementation supports flushing individual cache groups.
     316 * Determines whether the object cache implementation supports a particular feature.
    317317 *
    318318 * @since 6.1.0
    319319 *
    320  * @return bool True if group flushing is supported, false otherwise.
    321  */
    322 function wp_cache_supports_group_flush() {
     320 * @param string $feature Name of the feature to check for. Possible values include:
     321 *                        'add_multiple', 'set_multiple', 'get_multiple', 'delete_multiple',
     322 *                        'flush_runtime', 'flush_group'.
     323 * @return bool True if the feature is supported, false otherwise.
     324 */
     325function wp_cache_supports( $feature ) {
    323326    return false;
    324327}
Note: See TracChangeset for help on using the changeset viewer.