Currently the multilang filter breaks the cache system. The "lang" concept should be included in the mechanism to be able to cache contents when such filter is enabled.
New comment by Robert Brenstein:
With the introduction of unicode, the filter got rewritten and now works for all languages. So, this caching problem is gone and the following text has only historical value.
Written by Robert Brenstein:
I am not a proper Moodle developer, so I may be missing something very obvious, but since I was forced to occupy myself with functioning of format_text() function recently, I have also pondered the problem of caching multilang strings.
My interpretation of current setup is that multilang disables caching because the md5 key used by in the format_text() to identify cached entries is based on the text of cached items. In the case of filtered items, the text is changed by the filter called in the middle of format_text(), so the correct key cannot be ascerned upon entry to format_text(), that is before the text was processed by the filter. Catch 22 so to speak.
An approach to change this could be:
First, add language code to md5 key calculation in addition to all the $option parms that were recently added.
Second, base md5 key not on the filtered text but on the original text passed to the format_text() function.
These two combined should provide unique key values and catch all text and language changes while allowing the cache to function as expected.
In case dual behavior needs to be maintained, for example, to bypass caching when another filter is called, or to avoid any unexpected side-effects of this change, an extra parameter to format_text() function can be added, initialized as default to NULL, for example, so if it is NULL, the current behavior remains in effect. It would be then up to the caller to activate the alternative behavior. This approach would allow more than one alternative behavior.
A simpler variant could be for format_text() to check upon entry whether multilang filter is enabled and modify its behavior accordingly. In that case, adding the state of multilang filter to the string used to generate the md5 key would be desired.