Class CachingModule<T>
- java.lang.Object
-
- com.github.collinalpert.java2db.caching.CachingModule<T>
-
public class CachingModule<T> extends java.lang.ObjectA simple caching module, which is used for basic caching functionality. Its main task to cache query results.- Author:
- Collin Alpert
-
-
Constructor Summary
Constructors Constructor Description CachingModule()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TgetOrAdd(java.lang.String name, java.util.function.Supplier<T> valueFactory, java.time.Duration expiration)Gets an entry from the cache, or creates it if it does not exist using the passedvalueFactory.voidinvalidate()Invalidates, or "clears", the contents of this cache.voidinvalidate(java.lang.String name)Invalidates, or rather removes, a specific cache entry.
-
-
-
Method Detail
-
getOrAdd
public T getOrAdd(java.lang.String name, java.util.function.Supplier<T> valueFactory, java.time.Duration expiration)
Gets an entry from the cache, or creates it if it does not exist using the passedvalueFactory.- Parameters:
name- The name of the cache entry.valueFactory- TheSupplierof data, in case the cache does not have an entry or the entry is expired.expiration- The duration the cache is valid. After this duration is exceeded, the value will be cached from the passedvalueFactory- Returns:
- The requested value from the cache, if it exists. Otherwise the value from the
valueFactorywill be returned.
-
invalidate
public void invalidate()
Invalidates, or "clears", the contents of this cache.
-
invalidate
public void invalidate(java.lang.String name)
Invalidates, or rather removes, a specific cache entry. This will prompt a reload the next time a value with this cache name is requested.- Parameters:
name- The name of the entry in the cache.
-
-