Class CacheablePaginationResult<T extends BaseEntity>
- java.lang.Object
-
- com.github.collinalpert.java2db.paging.PaginationResult<T>
-
- com.github.collinalpert.java2db.paging.CacheablePaginationResult<T>
-
public class CacheablePaginationResult<T extends BaseEntity> extends PaginationResult<T>
Extended class that adds caching functionality to the pagination implementation.- Author:
- Collin Alpert
-
-
Field Summary
-
Fields inherited from class com.github.collinalpert.java2db.paging.PaginationResult
queries
-
-
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 aList.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.paging.PaginationResult
getNumberOfPages
-
-
-
-
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 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 Detail
-
getPage
public java.util.List<T> getPage(int number)
Gets a page by its identifier, or rather its number, an returns it as aList.- 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
public java.util.stream.Stream<T> getPageAsStream(int number)
Gets a page by its identifier, or rather its number, an returns it as aStream.- 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.
-
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.
-
-