Class CacheManager
java.lang.Object
com.expediagroup.transformer.cache.CacheManager
public final class CacheManager
extends java.lang.Object
Cache Utils class.
-
Constructor Summary
Constructors Constructor Description CacheManager()
-
Method Summary
Modifier and Type Method Description <T> void
cacheObject(java.lang.String cacheKey, T object)
Caches the given object.<T> void
cacheObject(java.lang.String cacheKey, T object, java.lang.Object defaultValue)
Caches the given object.<T> java.util.Optional<T>
getFromCache(java.lang.String cacheKey, java.lang.Class<? extends T> objectClass)
Retrieves an object from cache.void
removeFromCache(java.lang.String cacheKey)
Removes an object from cache.void
removeMatchingKeys(java.lang.String regex)
Removes all items matching with the given regex.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
CacheManager
public CacheManager()
-
-
Method Details
-
cacheObject
public <T> void cacheObject(java.lang.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(java.lang.String cacheKey, T object, java.lang.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> java.util.Optional<T> getFromCache(java.lang.String cacheKey, java.lang.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(java.lang.String cacheKey)Removes an object from cache.- Parameters:
cacheKey
- the cache key.
-
removeMatchingKeys
public void removeMatchingKeys(java.lang.String regex)Removes all items matching with the given regex.- Parameters:
regex
- the regex key.
-