We have an input filter that processes tokens within body fields such that the rendered output is slightly different depending on the user's language.
e.g. [node:123] gets rendered as a hyperlink to "My Attachment - 2.5MB" for English users and "Мой вложений - 2,5 Мб" for Russian Users.

Because entity cache is caching the result of the input filter processing and entity cache is not language aware, the dynamic nature of the input filter was not compatible with entity cache.

The attached patch alters entity cache so that a separate object is cached per language, making entity cache compatible with our custom input filter.

Others running multi language sites may benefit from this patch.

Possibly there are other scenarios where a site might benefit from caching more than one instance per entity based on user context (e.g. entity cache per role), in which case exposing a hook that allows the cid values to be altered could be a more flexible solution than this patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, entitycache_cache-per-language.patch, failed testing.

drasgardian’s picture

revised patch to account for the cache resets

Fabianx’s picture

Status: Needs work » Needs review

Go Testbot!

Status: Needs review » Needs work

The last submitted patch, entitycache_cache-per-language_2.patch, failed testing.

thtas’s picture

The attached update fixes an issue with expiring cache on delete/updates.
Cache resets on delete/update now clear all related language versions of the entity by use of the wildcard option in cache_clear_all

Berdir’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, entitycache_cache-per-language_3.patch, failed testing.

Pomliane’s picture

Status: Needs work » Needs review
FileSize
2.93 KB

Let's try to go further in the tests...

Simon Georges’s picture

Re-roll so the patch applies. Thanks to Pomliane for the debug.

This patch is part of the #1day1patch initiative.

Status: Needs review » Needs work

The last submitted patch, entitycache-1851430-8-cache_per_language.patch, failed testing.

drasgardian’s picture

Status: Needs work » Needs review
FileSize
5.12 KB

Updated patch to add cache resetting by wildcard for comments to address failed tests.

DamienMcKenna’s picture

Shouldn't it use entity_language() instead of the $language global?

vflirt’s picture

Hi,

i just tested this patch and it seems to work very well :)

I don't think it should not use entity_language because if you have entity_translation enabled and translate field values (that is the way i need and have setup ) then you are loading the entity for the current language and not for the entity language.

Kind Regards,
Dobromir

Dave Reid’s picture

Status: Needs review » Postponed (maintainer needs more info)

I don't think the proper fix here is to cache entities by language. The real problem is your text format filter needs to set the 'cache' flag in hook_filter_info() to FALSE to prevent caching the generated text output along with the entity.