Class TxFileOutputCacheDecorator

java.lang.Object
com.transifex.txnative.cache.TxDecoratorCache
com.transifex.txnative.cache.TxFileOutputCacheDecorator
All Implemented Interfaces:
TxCache

public class TxFileOutputCacheDecorator extends TxDecoratorCache
Decorator class responsible for storing any updates of the translations to a directory specified in the constructor.

Storing the translations happens asynchronously on a background thread after update(LocaleData.TranslationMap) is called.

  • Field Details

    • TAG

      public static final String TAG
  • Constructor Details

    • TxFileOutputCacheDecorator

      public TxFileOutputCacheDecorator(@NonNull File dstDirectory, @NonNull TxCache internalCache)
      Creates a new instance with a specific directory for storing the translations to the disk and an internal cache.
      Parameters:
      dstDirectory - The destination directory to write the translations to when the update(LocaleData.TranslationMap) is called.
      internalCache - The internal cache.
    • TxFileOutputCacheDecorator

      protected TxFileOutputCacheDecorator(@Nullable Executor executor, @NonNull File dstDirectory, @NonNull TxCache internalCache)
      Creates a new instance with a specific directory for storing the translations to the disk and an internal cache.
      Parameters:
      executor - The executor that will run the IO operations; if null is provided, Executors.newSingleThreadExecutor() is used.
      dstDirectory - The destination directory to write the translations to when the update(LocaleData.TranslationMap) is called.
      internalCache - The internal cache.
  • Method Details

    • update

      public void update(@NonNull LocaleData.TranslationMap translationMap)
      Updates the cache with the provided translations and writes them to the specified directory after clearing its content, if any.

      For the serialization and writing of the translations on disk, TranslationMapStorage is used internally. Each translation file uses "txstrings.json" as filename. Unlike TranslationMapStorage, pre-existing translations are not kept.

      Specified by:
      update in interface TxCache
      Overrides:
      update in class TxDecoratorCache