Make WordPress Core


Ignore:
Timestamp:
06/25/2026 09:08:14 AM (4 months ago)
Author:
gziolo
Message:

Allow customization of the AI Client object cache group

Introduces the wp_ai_client_cache_group filter to allow developers to customize the object cache group used by WP_AI_Client_Cache.

Includes tests for using a custom cache group and casting non-string filter values to strings.

Props baikaresandeep007-1, apermo.
Fixes #65127.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ai-client/wpAiClientCache.php

    r61700 r62557  
    219219                $this->assertSame( 'value1', $this->cache->get( 'key1' ) );
    220220        }
     221
     222        /**
     223         * Test that the cache group filter is respected.
     224         *
     225         * @ticket 65127
     226         */
     227        public function test_cache_group_filter_is_respected() {
     228                add_filter(
     229                        'wp_ai_client_cache_group',
     230                        function ( $group ) {
     231                                return 'wp_ai_client_tests_group';
     232                        }
     233                );
     234
     235                $set = $this->cache->set( 'ai_test_key', 'ai_value', 3600 );
     236                $this->assertTrue( $set );
     237
     238                $value = wp_cache_get( 'ai_test_key', 'wp_ai_client_tests_group' );
     239                $this->assertSame( 'ai_value', $value );
     240        }
     241
     242        /**
     243         * Test that a non-string cache group filter value is cast to string.
     244         *
     245         * @ticket 65127
     246         */
     247        public function test_cache_group_filter_returns_non_string() {
     248                add_filter(
     249                        'wp_ai_client_cache_group',
     250                        function ( $group ) {
     251                                return 12345;
     252                        }
     253                );
     254
     255                $set = $this->cache->set( 'ai_test_key', 'ai_value', 3600 );
     256                $this->assertTrue( $set );
     257
     258                $value = wp_cache_get( 'ai_test_key', '12345' );
     259                $this->assertSame( 'ai_value', $value );
     260        }
    221261}
Note: See TracChangeset for help on using the changeset viewer.