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.
Comments
Comment #2
drasgardian CreditAttribution: drasgardian commentedrevised patch to account for the cache resets
Comment #3
Fabianx CreditAttribution: Fabianx commentedGo Testbot!
Comment #5
thtas CreditAttribution: thtas commentedThe 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
Comment #6
BerdirComment #8
Pomliane CreditAttribution: Pomliane commentedLet's try to go further in the tests...
Comment #9
Simon Georges CreditAttribution: Simon Georges commentedRe-roll so the patch applies. Thanks to Pomliane for the debug.
This patch is part of the #1day1patch initiative.
Comment #11
drasgardian CreditAttribution: drasgardian commentedUpdated patch to add cache resetting by wildcard for comments to address failed tests.
Comment #12
DamienMcKennaShouldn't it use entity_language() instead of the $language global?
Comment #13
vflirt CreditAttribution: vflirt commentedHi,
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
Comment #14
Dave ReidI 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.