- Patch #503550 by yched, jp.stacey: make sure strings are cached per language.

merge-requests/26/head
Dries Buytaert 2010-02-27 07:41:34 +00:00
parent bb5dc9d0c4
commit 1a817fd2f8
3 changed files with 28 additions and 9 deletions

View File

@ -6197,6 +6197,8 @@ function drupal_check_incompatibility($v, $current_version) {
* to return an array with info about all types.
*/
function entity_get_info($entity_type = NULL) {
global $language;
// Use the advanced drupal_static() pattern, since this is called very often.
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
@ -6204,8 +6206,12 @@ function entity_get_info($entity_type = NULL) {
}
$entity_info = &$drupal_static_fast['entity_info'];
// hook_entity_info() includes translated strings, so each language is cached
// separately.
$langcode = $language->language;
if (empty($entity_info)) {
if ($cache = cache_get('entity_info')) {
if ($cache = cache_get("entity_info:$langcode")) {
$entity_info = $cache->data;
}
else {
@ -6235,7 +6241,7 @@ function entity_get_info($entity_type = NULL) {
}
// Let other modules alter the entity info.
drupal_alter('entity_info', $entity_info);
cache_set('entity_info', $entity_info);
cache_set("entity_info:$langcode", $entity_info);
}
}
@ -6252,7 +6258,8 @@ function entity_get_info($entity_type = NULL) {
*/
function entity_info_cache_clear() {
drupal_static_reset('entity_get_info');
cache_clear_all('entity_info', 'cache');
// Clear all languages.
cache_clear_all('entity_info:', 'cache', TRUE);
}
/**

View File

@ -65,18 +65,24 @@ function field_info_cache_clear() {
* as well as module, giving the module that exposes the entity type.
*/
function _field_info_collate_types($reset = FALSE) {
global $language;
static $info;
// @TODO use entity_get_info().
// The _info() hooks invoked below include translated strings, so each
// language is cached separately.
$langcode = $language->language;
if ($reset) {
$info = NULL;
cache_clear_all('field_info_types', 'cache_field');
// Clear all languages.
cache_clear_all('field_info_types:', 'cache_field', TRUE);
return;
}
if (!isset($info)) {
if ($cached = cache_get('field_info_types', 'cache_field')) {
if ($cached = cache_get("field_info_types:$langcode", 'cache_field')) {
$info = $cached->data;
}
else {
@ -144,7 +150,7 @@ function _field_info_collate_types($reset = FALSE) {
}
drupal_alter('field_storage_info', $info['storage types']);
cache_set('field_info_types', $info, 'cache_field');
cache_set("field_info_types:$langcode", $info, 'cache_field');
}
}

View File

@ -694,7 +694,7 @@ function image_style_flush($style) {
// Clear image style and effect caches.
cache_clear_all('image_styles', 'cache');
cache_clear_all('image_effects', 'cache');
cache_clear_all('image_effects:', 'cache', TRUE);
drupal_static_reset('image_styles');
drupal_static_reset('image_effects');
@ -825,10 +825,16 @@ function image_default_style_revert($style) {
* @see image_effect_definition_load()
*/
function image_effect_definitions() {
global $language;
// hook_image_effect_info() includes translated strings, so each language is
// cached separately.
$langcode = $language->language;
$effects = &drupal_static(__FUNCTION__);
if (!isset($effects)) {
if ($cache = cache_get('image_effects') && !empty($cache->data)) {
if ($cache = cache_get("image_effects:$langcode") && !empty($cache->data)) {
$effects = $cache->data;
}
else {
@ -844,7 +850,7 @@ function image_effect_definitions() {
};
}
uasort($effects, '_image_effect_definitions_sort');
cache_set('image_effects', $effects);
cache_set("image_effects:$langcode", $effects);
}
}