Package com.hotels.transformer.cache
Class CacheManager
java.lang.Object
com.hotels.transformer.cache.CacheManager
public final class CacheManager extends Object
Cache Utils class.
-
Constructor Summary
Constructors Constructor Description CacheManager()
-
Method Summary
Modifier and Type Method Description <T> void
cacheObject(String cacheKey, T object)
Caches the given object.<T> void
cacheObject(String cacheKey, T object, Object defaultValue)
Caches the given object.<T> Optional<T>
getFromCache(String cacheKey, Class<? extends T> objectClass)
Retrieves an object from cache.void
removeFromCache(String cacheKey)
Removes an object from cache.void
removeMatchingKeys(String regex)
Removes all items matching with the given regex.
-
Constructor Details
-
CacheManager
public CacheManager()
-
-
Method Details
-
cacheObject
Caches the given object.- Type Parameters:
T
- the class object type.- Parameters:
cacheKey
- the cache key.object
- the object to cache.
-
cacheObject
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
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
Removes an object from cache.- Parameters:
cacheKey
- the cache key.
-
removeMatchingKeys
Removes all items matching with the given regex.- Parameters:
regex
- the regex key.
-