Use override_load_textdomain for cache translation and improve performance

It seems your code is OK and won’t break anything but for it to work properly across different pages, maybe you should use Transient API functions instead of Object Cache counterparts.

Why?

Object Cache is not persistent by default (i.e. does not work across different pages). It will persist only if install an persistent cache plugin and a persistent cache backend (e.g. redis, memcached).

The Transient API worksa little bit “smarter”: it keeps the cached content on database to be used “persistently” if there’s no persistent object cache set, but will use the object cache API if there is an persistent cache backend and plugin.

Use the Transients API instead of these functions if you need to guarantee that your data will be cached. If persistent caching is configured, then the transients functions will use the wp_cache functions described in this document. However if persistent caching has not been enabled, then the data will instead be cached to the options table.

(source: https://codex.wordpress.org/Class_Reference/WP_Object_Cache )

Be aware that database performance may be affected, so, test and measure carefully.

Leave a Comment