PHP Caching

For best performance, TML should cache translations locally. Tml supports a number of various Cache adapters. To change cache settings add the following code to your initialization method call:

<?php tml_init(array(  
  "key" => YOUR_APPLICATION_KEY
  "cache" => array(
    "enabled" => true,
    "adapter" => "memcache",
    "host"    => "localhost",
    "port"    => "11211",
    "version_check_interval" => 3600
  )
); ?>

The cache will be stored in the cache/current.chdb file. Every time the cache is generated it will timestamp the folder so you will have a historic cache that you can fallback onto in case you need to rollback.

Memcache

Memcache is a self-building cache that lazily warms up by retrieving data from the TranslationExchange service and storing it on the Memcache server.

Prerequisites

You must have Memcache server running and accessible from your application.

You need to install the Memcache client library. This can be done using PECL:

$ pecl install memcache

Add "extension=memcache.so" to php.ini and restart your server.

Configuration

To change cache settings, modify config/config.json file.

<?php tml_init(array(  
  "key" => YOUR_APPLICATION_KEY,
  "cache" => array(
    "enabled" => true,
    "adapter" => "memcache",
    "host"    => "localhost",
    "port"    => "11211"
  )
); ?>

If you have multiple Memcache servers, you can add them as a list:

<?php tml_init(array(  
  "key" => YOUR_APPLICATION_KEY,
  "cache" => array(
    "enabled" => true,
    "adapter" => "memcache",
    "servers" => array(
      array("host" => "1.1.1.1", "port" => 11211),
      array("host" => "1.1.1.2", "port" => 11211),
      array("host" => "1.1.1.2", "port" => 11211)
    )
  )
); ?>

Memcached

Memcached is a self-building cache that lazily warms up by retrieving data from the TranslationExchange service and storing it on the Memcache server.

Prerequisites

You must have Memcache server running and accessible from your application.

You need to install the Memcached client library. On linux, this can be done using:

sudo apt-get install php5-memcached  

Or using PECL:

$ sudo pecl install memcached

Add "extension=memcached.so" to php.ini and restart your server.

If you are on a Mac, you may need to download the latest libmemcached client library. Once downloaded, extract the archive and run the following commands:

$ ./configure
$ make
$ sudo make install

After that you can proceed with the PECL installation.

Configuration

To change cache settings, modify config/config.json file.

<?php tml_init(array(  
  "key" => YOUR_APPLICATION_KEY,
  "cache" => array(
    "enabled" => true,
    "adapter" => "memcached",
    "host"    => "localhost",
    "port"    => "11211"
  )
); ?>

If you have multiple Memcache servers, you can add them as a list:

<?php tml_init(array(  
  "key" => YOUR_APPLICATION_KEY,
  "cache" => array(
    "enabled" => true,
    "adapter" => "memcached",
    "servers" => array(
      array("host" => "1.1.1.1", "port" => 11211),
      array("host" => "1.1.1.2", "port" => 11211),
      array("host" => "1.1.1.2", "port" => 11211)
    )
  )
); ?>

Redis

Redis is a self-building persistent cache that lazily warms up by retrieving data from the TranslationExchange service and storing it on the Redis server.

Prerequisites

You must have Redis running and accessible from your server.

Install the phpredis extension:

$ git clone https://github.com/nicolasff/phpredis
$ cd phpredis
$ phpsize
$ ./configure
$ make
$ sudo make install

Add "extension=redis.so" to php.ini and restart your Apache server.

Configuration

To change cache settings, modify config/config.json file.

<?php tml_init(array(  
  "key" => YOUR_APPLICATION_KEY,
  "cache" => array(
    "enabled" => true,
    "adapter" => "redis",
    "host"    => "localhost",
    "port"    => "6379"
  )
); ?>

You can also connect to Redis using a socket:

<?php tml_init(array(  
  "key" => YOUR_APPLICATION_KEY,
  "cache" => array(
    "enabled" => true,
    "adapter" => "redis",
    "socket"  => "/tmp/redis.sock"
  )
); ?>

APC

APC is a self-building cache that lazily warms up by retrieving data from the Tml service and storing it in the APC store.

Configuration

<?php tml_init(array(  
  "key" => YOUR_APPLICATION_KEY,
  "cache" => array(
    "enabled" => true,
    "adapter" => "apc"
  )
); ?>

File System

This is a readonly cache that must be generated during deploy time.

Configuration

<?php tml_init(array(  
  "key" => YOUR_APPLICATION_KEY,
  "cache" => array(
    "enabled" => true,
    "adapter" => "file",
    "path"    => "/cache"
  )
); ?>

Generation

To generate the cache files, run the following script:

$ bin/tml

The files will be stored in the /cache/{version} folder. Every time the cache is generated it will timestamp the folder so you will have a historic cache that you can fallback onto in case you need to rollback.