polylang / dynamo

Improves the WordPress translations performance
GNU General Public License v2.0
6 stars 1 forks source link

Add object cache support #10

Closed Chouby closed 2 years ago

Chouby commented 2 years ago

This PR adds a new way to load MO files. As in WordPress, all translations of a given file are loaded in memory. However they are stored in an array of strings rather than an array of Translation_Entry objects. Thus, the performance is improved both when reading the file (it's faster to store a string in an array rather than creating a Translation_Entry object) and when translating strings.

Although this new method is faster than the method used in WordPress, processing the complete file is still slower than the dynamic method in use in v1.0. It becomes very fast if we don't have to read and parse the translation file. That's why, by default, the method is activated only when an external object cache is available.

The method can be programmatically selected with the filter dynamo_file_loader.

The cache expiration limit is set to 12 hours by default and is programmatically filterable with the filter dynamo_cache_expire. In any case, the cache is cleaned at each update (WordPress, theme, plugins or language packs).

The cache is common to all sites for multisite.

As a side effect of this development, the check for file readabibility has been moved to the MO classes.