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
-
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 aList.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 aStream.voidinvalidateCache(java.lang.String name)Marks a specific value in the cache as invalid.voidinvalidateCaches()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
-
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 thecreatePaginationmethods in theBaseService- 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
Gets a page by its identifier, or rather its number, an returns it as aList. 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:
getPagein classPaginationResult<T extends BaseEntity>- Parameters:
number- The number of the page. The first page has the index 1.- Returns:
- A
Listof entities which are displayed on the requested page.
-
getPageAsStream
Gets a page by its identifier, or rather its number, an returns it as aStream. 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:
getPageAsStreamin classPaginationResult<T extends BaseEntity>- Parameters:
number- The number of the page. The first page has the index 1.- Returns:
- A
Streamof entities which are displayed on the requested page.
-
getPageAsArray
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:
getPageAsArrayin classPaginationResult<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 toinvalidateCache(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.
-