Express Caching

For the best performance translations should be cached in your application. There are multiple different adapters supported for caching, including: Memcache, Redis & File based . You can specify the adapter type and configuration settings in tml.init().

Cache Adapters

Cache Options

Cache Adapters

Memcache

app.use(tml.init({  
  key: "YOUR-PROJECT-KEY",
  cache: {
    adapter: "memcache",
    hosts: ["localhost:11211"]
  })
});

Redis

Similarly, to use redis, specify your servers as follows:

app.use(tml.init({  
  key: "YOUR-PROJECT-KEY",
  cache: {
    adapter: "redis",
    host: "localhost",
    port: 6379
  })
});

Additional attributes include: timeout, namespace and version.

Files

To use file based caching, first download a release from the service and unzip it in a desired location, then use:

app.use(tml.init({  
  key: "YOUR-PROJECT-KEY",
  cache: {
    adapter: "file",
    path: "./cache"
  })
});

Cache Options

Invalidation

By default, the server will check for new cache version on the CDN every hour. This time can be manually configured using the cache options.

app.use(tml.init({  
  key: "YOUR-PROJECT-KEY",
  cache: {
    ...
    version_check_interval: 60 * 10,
    ...
  })
});

The value is specified in seconds. So in the above example, the version will be checked every 10 minutes.

Namespace

If you want to keep all of the translation cache keys in their own namespace, you can set it as a "namespace" option.

app.use(tml.init({  
  key: "YOUR-PROJECT-KEY",
  cache: {
    ...
    namespace: 'translations',
    ... 
  })
});