Search code examples
phpcakephpapc

Performance, apc define constants or apc fetch on language file


Today i have a new very weird question. I am trying to find a way to cache language pot files.

The standard way that CakePHP does this is it parses the file into an array and then returns the key value pair. I am looking at increasing the performance for this due to the file growing exponentially

I have four solutions for this but i don't know which of them will be easily maintainable and supply the fastest performance.

Option 1: Use CakePHP's standard method for translations but just split the files up a little bit and use the __d() function

Option 2: Use a class i wrote to parse the contents of all the langauge files and cache them using apc. Then retrieve the translation via apc_fetch

Option 3: Serialize the translation array using either serialize or json_encode (which ever works the fastest) and defining it using apc_define_contants

Option 4: Use apc_define_contants to define every key in the translation file as a contant with its value

I am stuck on this and i don't know what will be best


Solution

  • I can point you to some other possible solutions:

    1. Cache them in memcache - nice if you have some (enough) RAM
    2. Cache them in fatcache - a nice one if you have SSDs on your server
    3. Serve them from Redis - Since Redis is a very fast key-value store you should be able to move all your transalations to it, or just parse the .po/.pot files and "cache" them in redis. However with these approaches you will have to see how exactly to handle the cache and where to attach/retrieve it. There are a RedisEngine and MemcacheEngine in CakePHP.

    Maybe your best solution would be some in-memory cache, like memcache.