Class CacheManager

java.lang.Object
com.hotels.transformer.cache.CacheManager

public final class CacheManager
extends Object
Cache Utils class.
  • Constructor Details

    • CacheManager

      public CacheManager()
  • Method Details

    • cacheObject

      public <T> void cacheObject​(String cacheKey, T object)
      Caches the given object.
      Type Parameters:
      T - the class object type.
      Parameters:
      cacheKey - the cache key.
      object - the object to cache.
    • cacheObject

      public <T> void cacheObject​(String cacheKey, T object, Object defaultValue)
      Caches the given object.
      Type Parameters:
      T - the class object type.
      Parameters:
      cacheKey - the cache key.
      object - the object to cache.
      defaultValue - a default value to add to cache if the object it null
    • getFromCache

      public <T> Optional<T> getFromCache​(String cacheKey, Class<? extends T> objectClass)
      Retrieves an object from cache.
      Type Parameters:
      T - the class object type.
      Parameters:
      cacheKey - the cache key.
      objectClass - the class of the object to return.
      Returns:
      the cached object or Optional.empty() if not existing.
    • removeFromCache

      public void removeFromCache​(String cacheKey)
      Removes an object from cache.
      Parameters:
      cacheKey - the cache key.
    • removeMatchingKeys

      public void removeMatchingKeys​(String regex)
      Removes all items matching with the given regex.
      Parameters:
      regex - the regex key.