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.

git-svn-id: https://develop.svn.wordpress.org/trunk@57831 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2024-03-14 09:04:00 +00:00
parent 0c24793d25
commit 8fafc3acae
3 changed files with 20 additions and 19 deletions

View File

@ -183,8 +183,8 @@ class WP_Textdomain_Registry {
return $files;
}
$cache_key = 'cached_mo_files_' . md5( $path );
$files = wp_cache_get( $cache_key, 'translations' );
$cache_key = md5( $path );
$files = wp_cache_get( $cache_key, 'translation_files' );
if ( false === $files ) {
$files = glob( $path . '*.mo' );
@ -197,7 +197,7 @@ class WP_Textdomain_Registry {
$files = array_merge( $files, $php_files );
}
wp_cache_set( $cache_key, $files, 'translations' );
wp_cache_set( $cache_key, $files, 'translation_files', HOUR_IN_SECONDS );
}
return $files;
@ -246,13 +246,13 @@ class WP_Textdomain_Registry {
foreach ( $translation_types as $type ) {
switch ( $type ) {
case 'plugin':
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
wp_cache_delete( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' );
break;
case 'theme':
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' );
wp_cache_delete( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' );
break;
default:
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' );
wp_cache_delete( md5( WP_LANG_DIR . '/' ), 'translation_files' );
break;
}
}

View File

@ -876,6 +876,7 @@ function wp_start_object_cache() {
'site-queries',
'site-transient',
'theme_files',
'translation_files',
'rss',
'users',
'user-queries',

View File

@ -19,10 +19,10 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
}
public function tear_down() {
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar/' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' );
wp_cache_delete( md5( WP_LANG_DIR . '/foobar/' ), 'translation_files' );
wp_cache_delete( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' );
wp_cache_delete( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' );
wp_cache_delete( md5( WP_LANG_DIR . '/' ), 'translation_files' );
parent::tear_down();
}
@ -49,7 +49,7 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
'Custom path for textdomain not returned'
);
$this->assertNotFalse(
wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/bar/' ), 'translations' ),
wp_cache_get( md5( WP_LANG_DIR . '/bar/' ), 'translation_files' ),
'List of files in custom path not cached'
);
}
@ -89,10 +89,10 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/themes/' );
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/' );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' ) );
$this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' ) );
$this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/foobar/' ), 'translation_files' ) );
$this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/' ), 'translation_files' ) );
}
/**
@ -103,7 +103,7 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
$result = $this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins/' );
remove_filter( 'pre_get_language_files_from_path', '__return_empty_array' );
$cache = wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
$cache = wp_cache_get( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' );
$this->assertEmpty( $result );
$this->assertFalse( $cache );
@ -144,9 +144,9 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
)
);
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' ) );
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ) );
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ) );
$this->assertFalse( wp_cache_get( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' ) );
$this->assertFalse( wp_cache_get( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' ) );
$this->assertFalse( wp_cache_get( md5( WP_LANG_DIR . '/' ), 'translation_files' ) );
}
public function data_domains_locales() {