mirror of
git://develop.git.wordpress.org/
synced 2025-02-22 23:54:09 +01:00
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:
parent
0c24793d25
commit
8fafc3acae
@ -183,8 +183,8 @@ class WP_Textdomain_Registry {
|
|||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache_key = 'cached_mo_files_' . md5( $path );
|
$cache_key = md5( $path );
|
||||||
$files = wp_cache_get( $cache_key, 'translations' );
|
$files = wp_cache_get( $cache_key, 'translation_files' );
|
||||||
|
|
||||||
if ( false === $files ) {
|
if ( false === $files ) {
|
||||||
$files = glob( $path . '*.mo' );
|
$files = glob( $path . '*.mo' );
|
||||||
@ -197,7 +197,7 @@ class WP_Textdomain_Registry {
|
|||||||
$files = array_merge( $files, $php_files );
|
$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;
|
return $files;
|
||||||
@ -246,13 +246,13 @@ class WP_Textdomain_Registry {
|
|||||||
foreach ( $translation_types as $type ) {
|
foreach ( $translation_types as $type ) {
|
||||||
switch ( $type ) {
|
switch ( $type ) {
|
||||||
case 'plugin':
|
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;
|
break;
|
||||||
case 'theme':
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' );
|
wp_cache_delete( md5( WP_LANG_DIR . '/' ), 'translation_files' );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -876,6 +876,7 @@ function wp_start_object_cache() {
|
|||||||
'site-queries',
|
'site-queries',
|
||||||
'site-transient',
|
'site-transient',
|
||||||
'theme_files',
|
'theme_files',
|
||||||
|
'translation_files',
|
||||||
'rss',
|
'rss',
|
||||||
'users',
|
'users',
|
||||||
'user-queries',
|
'user-queries',
|
||||||
|
@ -19,10 +19,10 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function tear_down() {
|
public function tear_down() {
|
||||||
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar/' ), 'translations' );
|
wp_cache_delete( md5( WP_LANG_DIR . '/foobar/' ), 'translation_files' );
|
||||||
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
|
wp_cache_delete( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' );
|
||||||
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' );
|
wp_cache_delete( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' );
|
||||||
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' );
|
wp_cache_delete( md5( WP_LANG_DIR . '/' ), 'translation_files' );
|
||||||
|
|
||||||
parent::tear_down();
|
parent::tear_down();
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
|
|||||||
'Custom path for textdomain not returned'
|
'Custom path for textdomain not returned'
|
||||||
);
|
);
|
||||||
$this->assertNotFalse(
|
$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'
|
'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 . '/themes/' );
|
||||||
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/' );
|
$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( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' ) );
|
||||||
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ) );
|
$this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' ) );
|
||||||
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar/' ), 'translations' ) );
|
$this->assertNotFalse( wp_cache_get( md5( WP_LANG_DIR . '/foobar/' ), 'translation_files' ) );
|
||||||
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ) );
|
$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/' );
|
$result = $this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins/' );
|
||||||
remove_filter( 'pre_get_language_files_from_path', '__return_empty_array' );
|
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->assertEmpty( $result );
|
||||||
$this->assertFalse( $cache );
|
$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( md5( WP_LANG_DIR . '/plugins/' ), 'translation_files' ) );
|
||||||
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ) );
|
$this->assertFalse( wp_cache_get( md5( WP_LANG_DIR . '/themes/' ), 'translation_files' ) );
|
||||||
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ) );
|
$this->assertFalse( wp_cache_get( md5( WP_LANG_DIR . '/' ), 'translation_files' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function data_domains_locales() {
|
public function data_domains_locales() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user