質問

I have been using PHP's gettext extension for a while and I am satisfied with its capabilities. I was wondering if there was a point in writing a class that will cache the strings from the .mo file to a Memcached server, for example.

Can I benefit from caching strings, collected by gettext or should I leave it as it is?

役に立ちましたか?

解決

No benefits

No, you can't benefit from caching your .mo files to external cache like Memcached. The native gettext extension have its own caching built-in. Due to the fact that PHP's gettext functions retrieve translation only from a .mo file, makes it impossible for PHP to get the translations from a Memcached server.


The wrong solution

The only option is to cache the strings from your .mo file as a string array in your Memcached server, but that would make the method of getting translations slower than the native one, so there is no point in making that.


Conclusion

Use the native gettext, it has its own caching algorithms. Loading up your code with external caching classes may result in useless code, which will slow down your site performance, rather than making it faster. Moreover, you will already have lost your time writing the external caching class.

他のヒント

If you're using the native gettext extension, it is already caching .mo files internally. You'll find many a question on here on how to get it to refresh because its cache can be so aggressive sometimes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top