Class CachingModule<T>


  • public class CachingModule<T>
    extends Object
    A helper module which contains functionality for basic caching. Its main task to cache query results.
    Author:
    Collin Alpert
    • Constructor Detail

      • CachingModule

        public CachingModule()
    • Method Detail

      • getOrAdd

        public T getOrAdd​(String name,
                          Supplier<T> valueFactory,
                          Duration expiration)
        Gets an entry from the cache, or creates it if it does not exist using the passed valueFactory.
        Parameters:
        name - The name of the cache entry.
        valueFactory - The Supplier of 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 passed valueFactory
        Returns:
        The requested value from the cache, if it exists. Otherwise the value from the valueFactory will be returned.
      • invalidate

        public void invalidate()
        Invalidates, or "clears", the contents of this cache.
      • invalidate

        public void invalidate​(String name)
        Invalidates, or rather removes, a specific cache entry. This will prompt a reload from the database the next time a value with this cache name is requested.
        Parameters:
        name - The name of the entry in the cache.