Class CacheablePaginationResult<T extends BaseEntity>


  • public class CacheablePaginationResult<T extends BaseEntity>
    extends PaginationResult<T>
    Extended class that adds caching functionality to the pagination implementation.
    Author:
    Collin Alpert
    • Constructor Summary

      Constructors 
      Constructor Description
      CacheablePaginationResult​(java.util.List<Query<T>> queries, java.time.Duration cacheExpiration)
      Constructor that allows the creation of a cached pagination.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<T> getPage​(int number)
      Gets a page by its identifier, or rather its number, an returns it as a List.
      java.util.stream.Stream<T> getPageAsStream​(int number)
      Gets a page by its identifier, or rather its number, an returns it as a Stream.
      void invalidateCache​(java.lang.String name)
      Marks a specific value in the cache as invalid.
      void invalidateCaches()
      Marks the entire cache of the pagination as invalid, causing a reload the next time and value is requested.
      • Methods inherited from class java.lang.Object

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

      • CacheablePaginationResult

        public CacheablePaginationResult​(java.util.List<Query<T>> queries,
                                         java.time.Duration cacheExpiration)
        Constructor that allows the creation of a cached pagination. To obtain an instance, please use the createPagination methods in the BaseService
        Parameters:
        queries - The queries that represent the operations of retrieving specific pages from the database.
        cacheExpiration - The duration a query result is valid for in the cache.
    • Method Detail

      • getPage

        public java.util.List<T> getPage​(int number)
        Gets a page by its identifier, or rather its number, an returns it as a List.
        Overrides:
        getPage in class PaginationResult<T extends BaseEntity>
        Parameters:
        number - The number of the page. The first page has the index 1.
        Returns:
        A List of entities which are displayed on the requested page.
      • getPageAsStream

        public java.util.stream.Stream<T> getPageAsStream​(int number)
        Gets a page by its identifier, or rather its number, an returns it as a Stream.
        Overrides:
        getPageAsStream in class PaginationResult<T extends BaseEntity>
        Parameters:
        number - The number of the page. The first page has the index 1.
        Returns:
        A Stream of entities which are displayed on the requested page.
      • invalidateCaches

        public void invalidateCaches()
        Marks the entire cache of the pagination as invalid, causing a reload the next time and value is requested. This call is equivalent to invalidateCache(null).
      • invalidateCache

        public void invalidateCache​(java.lang.String name)
        Marks a specific value in the cache as invalid. This will cause a reload of the value the next time it is requested from the cache.
        Parameters:
        name - The name, or rather the page number, of the value in the cache.