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
  • Field Summary

    Fields inherited from class com.github.collinalpert.java2db.pagination.PaginationResult

    queries
  • Constructor Summary

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

    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.
    T[] getPageAsArray​(int number)
    Gets a page by its identifier, or rather its number, an returns it as an array.
    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 com.github.collinalpert.java2db.pagination.PaginationResult

    getNumberOfPages, getPageAsArrayAsync, getPageAsStreamAsync, getPageAsync, orderBy, orderBy

    Methods inherited from class java.lang.Object

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

    • CacheablePaginationResult

      public CacheablePaginationResult​(java.util.List<EntityQuery<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 Details

    • 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. 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 java.util.stream.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​(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.