Class CachingModule<T>


  • public class CachingModule<T>
    extends java.lang.Object
    A 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
      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 passed valueFactory.
      void invalidate()
      Invalidates, or "clears", the contents of this cache.
      void invalidate​(java.lang.String name)
      Invalidates, or rather removes, a specific cache entry.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CachingModule

        public CachingModule()
    • 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 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​(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.