Class CacheablePaginationResult<T extends BaseEntity>

java.lang.Object
com.github.collinalpert.java2db.pagination.PaginationResult<T>
com.github.collinalpert.java2db.pagination.CacheablePaginationResult<T>

public class CacheablePaginationResult<T extends BaseEntity>
extends PaginationResult<T>
Extended class that adds caching functionality to the pagination implementation. Note that caching will not be available for pages that are fetched asynchronously.
Author:
Collin Alpert
  • Constructor Details

    • CacheablePaginationResult

      public CacheablePaginationResult​(List<EntityQuery<T>> queries, 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 Details

    • getPage

      public List<T> getPage​(int number)
      Gets a page by its identifier, or rather its number, an returns it as a List. If this particular page has already been requested and has not expired yet, it will be returned from the in-memory cache. Otherwise it will be fetched from the database.
      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 Stream<T> getPageAsStream​(int number)
      Gets a page by its identifier, or rather its number, an returns it as a Stream. If this particular page has already been requested and has not expired yet, it will be returned from the in-memory cache. Otherwise it will be fetched from the database.
      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.
    • getPageAsArray

      public T[] getPageAsArray​(int number)
      Gets a page by its identifier, or rather its number, an returns it as an array. If this particular page has already been requested and has not expired yet, it will be returned from the in-memory cache. Otherwise it will be fetched from the database.
      Overrides:
      getPageAsArray in class PaginationResult<T extends BaseEntity>
      Parameters:
      number - The number of the page. The first page has the index 1.
      Returns:
      An array 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​(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.