public interface InternalCache
An internal interface for Http's cache. Applications should not implement this interface directly. Instead, they
should use
Cache to configure a cache for an Httpd instance.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Method Summary
Modifier and TypeMethodDescriptionReturns the cached response for the givenrequest, or null if no cached response exists or is not suitable.Stores the givenresponsein the cache and returns aCacheRequestto write the response body, or null if the response cannot be cached.voidRemoves any cached entries for the givenrequest.voidTracks a conditional GET that was satisfied by this cache.voidtrackResponse(CacheStrategy cacheStrategy) Tracks an HTTP response that was satisfied by the givencacheStrategy.voidUpdates the stored cached response with headers from the newnetworkresponse.
-
Method Details
-
get
Returns the cached response for the givenrequest, or null if no cached response exists or is not suitable.- Parameters:
request- The request to get the cached response for.- Returns:
- The cached response, or null.
- Throws:
IOException- if an I/O error occurs.
-
put
Stores the givenresponsein the cache and returns aCacheRequestto write the response body, or null if the response cannot be cached.- Parameters:
response- The response to store.- Returns:
- A
CacheRequestto write the response body, or null. - Throws:
IOException- if an I/O error occurs.
-
remove
Removes any cached entries for the givenrequest. This is called when the client invalidates the cache, such as when making a POST, PUT, or DELETE request.- Parameters:
request- The request to remove from the cache.- Throws:
IOException- if an I/O error occurs.
-
update
Updates the stored cached response with headers from the newnetworkresponse. This is called to handle conditional requests. If the stored response has changed sincecachedwas returned, this does nothing.- Parameters:
cached- The stale cached response.network- The new network response.
-
trackConditionalCacheHit
void trackConditionalCacheHit()Tracks a conditional GET that was satisfied by this cache. This is used for statistics. -
trackResponse
Tracks an HTTP response that was satisfied by the givencacheStrategy. This is used for statistics.- Parameters:
cacheStrategy- The cache strategy used for the response.
-