Make WordPress Core

Changeset 57831


Ignore:
Timestamp:
03/14/2024 09:04:00 AM (2 months ago)
Author:
swissspidy
Message:

I18N: Improve translation file cache group & expiration.

Adds an explicit 1 hour expiration for the translation file cache introduced in [57287] / #58919.
This prevents stale caches when a site does not use the regular way of installing language packs, for example when an atomic filesystem is involved.
Also configures the translation_files group as a global cache group on multisite.

Props dd32.
Fixes #60764.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-textdomain-registry.php

    r57639 r57831  
    184184        }
    185185
    186         $cache_key = 'cached_mo_files_' . md5( $path );
    187         $files     = wp_cache_get( $cache_key, 'translations' );
     186        $cache_key = md5( $path );
     187        $files     = wp_cache_get( $cache_key, 'translation_files' );
    188188
    189189        if ( false === $files ) {
     
    198198            }
    199199
    200             wp_cache_set( $cache_key, $files, 'translations' );
     200            wp_cache_set( $cache_key, $files, 'translation_files', HOUR_IN_SECONDS );
    201201        }
    202202
     
    247247            switch ( $type ) {
    248248                case 'plugin':
    249                     wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
     249                    wp_cache_delete( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' );
    250250                    break;
    251251                case 'theme':
    252                     wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' );
     252                    wp_cache_delete( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' );
    253253                    break;
    254254                default:
    255                     wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' );
     255                    wp_cache_delete( md5( WP_LANG_DIR . '/' ), 'translation_files' );
    256256                    break;
    257257            }
  • trunk/src/wp-includes/load.php

    r57773 r57831  
    877877                'site-transient',
    878878                'theme_files',
     879                'translation_files',
    879880                'rss',
    880881                'users',
  • trunk/tests/phpunit/tests/l10n/wpTextdomainRegistry.php

    r57516 r57831  
    2020
    2121    public function tear_down() {
    22         wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar/' ), 'translations' );
    23         wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
    24         wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' );
    25         wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' );
     22        wp_cache_delete( md5( WP_LANG_DIR . '/foobar/' ), 'translation_files' );
     23        wp_cache_delete( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' );
     24        wp_cache_delete( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' );
     25        wp_cache_delete( md5( WP_LANG_DIR . '/' ), 'translation_files' );
    2626
    2727        parent::tear_down();
     
    5050        );
    5151        $this->assertNotFalse(
    52             wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/bar/' ), 'translations' ),
     52            wp_cache_get( md5( WP_LANG_DIR . '/bar/' ), 'translation_files' ),
    5353            'List of files in custom path not cached'
    5454        );
     
    9090        $this->instance->get_language_files_from_path( WP_LANG_DIR . '/' );
    9191
    92         $this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' ) );
    93         $this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ) );
    94         $this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar/' ), 'translations' ) );
    95         $this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ) );
     92        $this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' ) );
     93        $this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' ) );
     94        $this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/foobar/' ), 'translation_files' ) );
     95        $this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/' ), 'translation_files' ) );
    9696    }
    9797
     
    104104        remove_filter( 'pre_get_language_files_from_path', '__return_empty_array' );
    105105
    106         $cache = wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
     106        $cache = wp_cache_get( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' );
    107107
    108108        $this->assertEmpty( $result );
     
    145145        );
    146146
    147         $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' ) );
    148         $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ) );
    149         $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ) );
     147        $this->assertFalse( wp_cache_get( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' ) );
     148        $this->assertFalse( wp_cache_get( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' ) );
     149        $this->assertFalse( wp_cache_get( md5( WP_LANG_DIR . '/' ), 'translation_files' ) );
    150150    }
    151151
Note: See TracChangeset for help on using the changeset viewer.