public class ResponseCache
extends java.lang.Object
It caches all Responses with their matching identifiers. This reduces CPU cycles and the time to wait for loading the pages. This is especially useful in situations where multiple clients are accessing the server.
Modifier and Type | Method and Description |
---|---|
static void |
cacheResponse(java.lang.String identifier,
java.util.function.Supplier<Response> loader)
Puts the page into the page cache.
|
static void |
clearCache()
Clears the cache from all its contents.
|
static void |
clearResponse(java.lang.String identifier) |
static java.util.Set<java.lang.String> |
getCacheKeys() |
static long |
getEstimatedSize() |
static boolean |
isCached(java.lang.String identifier)
Checks if the page is cached.
|
static Response |
loadResponse(java.lang.String identifier)
Loads the page from the page cache.
|
static Response |
loadResponse(java.lang.String identifier,
java.util.function.Supplier<Response> loader)
Loads the response from the response cache.
|
public static Response loadResponse(java.lang.String identifier, java.util.function.Supplier<Response> loader)
If the Response
isn't cached, Supplier.get()
in the loader
is called to create the Response.
If the Response is created, it's automatically cached.
public static Response loadResponse(java.lang.String identifier)
identifier
- The identifier of the pagenull
if it wasn'tpublic static void cacheResponse(java.lang.String identifier, java.util.function.Supplier<Response> loader)
If the cache already inherits that identifier
, it's renewed.
identifier
- The identifier of the pageloader
- The Response
Supplier
(How it should load the page)public static boolean isCached(java.lang.String identifier)
identifier
- The identifier of the pagepublic static void clearCache()
public static java.util.Set<java.lang.String> getCacheKeys()
public static long getEstimatedSize()
public static void clearResponse(java.lang.String identifier)