Class TxDecoratorCache

java.lang.Object
com.transifex.txnative.cache.TxDecoratorCache
All Implemented Interfaces:
TxCache
Direct Known Subclasses:
TxFileOutputCacheDecorator, TxProviderBasedCache, TxReadonlyCacheDecorator, TxUpdateFilterCache

public class TxDecoratorCache extends Object implements TxCache
Decorator class managing an internal cache and propagating the get() and update() protocol method calls to said cache. The class should be extended to add new capabilities.
  • Field Details

    • mInternalCache

      protected final TxCache mInternalCache
  • Constructor Details

    • TxDecoratorCache

      public TxDecoratorCache(@NonNull TxCache internalCache)
      Creates a decorator with the provided cache.
      Parameters:
      internalCache - The cache to be used.
  • Method Details

    • get

      Description copied from interface: TxCache
      Gets all translations from the cache in the form of a TranslationMap object.

      The returned object should not be altered as the cache may use it internally.

      Specified by:
      get in interface TxCache
    • get

      @Nullable public String get(@NonNull String key, @NonNull String locale)
      Description copied from interface: TxCache
      Get the translation for a certain key and locale pair.
      Specified by:
      get in interface TxCache
      Parameters:
      key - The key of the string.
      locale - The locale code.
      Returns:
      The string if the key was found in the cache; null if the provided locale does not exist in the cache or the key does not exist for this locale; empty string if the string has not yet been translated for this locale
    • update

      public void update(@NonNull LocaleData.TranslationMap translationMap)
      Description copied from interface: TxCache
      Update the cache with the provided TranslationMap.

      The translation map should not be changed after providing it to the cache, because the cache implementation may use it without making a copy.

      Specified by:
      update in interface TxCache