public class PageCache extends 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.
This cache uses the Google Guava Cache
.
Modifier and Type | Method and Description |
---|---|
static void |
cachePage(String identifier,
PageLoader loader)
Puts the page into the page cache.
|
static void |
clearCache()
Clears the cache from all its contents.
|
static boolean |
isCached(String identifier)
Checks if the page is cached.
|
static Response |
loadPage(String identifier)
Loads the page from the page cache.
|
static Response |
loadPage(String identifier,
PageLoader loader)
Loads the page from the page cache.
|
static void |
removeIf(Predicate<String> filter)
Removes all of the elements of this cache that satisfy the given predicate.
|
public static Response loadPage(String identifier, PageLoader loader)
If the Response
isn't cached, PageLoader.createResponse()
in the loader
is called to create the Response.
If the Response is created, it's automatically cached.
identifier
- The identifier of the pageloader
- The PageLoader
(How should it load the page if it's not cached)loader
public static Response loadPage(String identifier)
identifier
- The identifier of the pagenull
if it wasn'tpublic static void cachePage(String identifier, PageLoader loader)
If the cache already inherits that identifier
, it's renewed.
identifier
- The identifier of the pageloader
- The PageLoader
(How it should load the page)public static boolean isCached(String identifier)
identifier
- The identifier of the pagepublic static void removeIf(Predicate<String> filter)
filter
- a predicate which returns true for entries to be removedpublic static void clearCache()
Copyright © 2017. All rights reserved.