HttpCache class
An in-memory, LRU, shared HTTP cache following RFC 9111.
It decides (lookup) and stores (store, refresh); moving bytes is the
job of a relay such as CachingHttpRelay. Only GET (and HEAD, served
from GET entries) of HTTP/1.1 requests without Authorization, Range or
a body participate; see whyNotStorable for what is kept.
Constructors
- HttpCache(HttpCacheOptions options, {HttpCacheBudget? budget, DateTime now()?})
-
Creates a cache with
options, optionally sharingbudget.
Properties
- budget → HttpCacheBudget?
-
The shared budget this cache also counts against, if any.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- now → DateTime Function()
-
The clock.
final
- options → HttpCacheOptions
-
The cache's behaviour and limits.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stats → HttpCacheStats
-
The current counters.
no setter
Methods
-
canServeStaleOnError(
HttpCacheEntry entry, HttpRequestHead request, {DateTime? at}) → bool -
Whether stale
entrymay answerrequestbecause the origin failed (RFC 5861stale-if-error=N, in the response or the request): it must be at most N seconds past its freshness lifetime. -
clear(
) → void - Drops every entry (e.g. when the owning tunnel closes).
-
invalidate(
String key) → void -
Drops every variant stored under
key. -
lookup(
HttpRequestHead request, {DateTime? at}) → CacheLookup -
Decides how
requestuses the cache atat(default: now). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recordBypass(
) → void - Counts a bypassed request.
-
recordHit(
) → void - Counts a served hit.
-
recordMiss(
) → void - Counts a miss.
-
recordRevalidated(
) → void - Counts a successful revalidation.
-
refresh(
HttpCacheEntry entry, HttpResponseHead notModified, {required DateTime requestTime, required DateTime responseTime}) → void -
Refreshes
entryfrom a304 Not ModifiednotModified(RFC 9111 §4.3.4): its fields replace the stored ones and freshness restarts. An update that makes the entryno-storedrops it. -
store(
{required HttpRequestHead request, required HttpResponseHead response, required Uint8List body, required DateTime requestTime, required DateTime responseTime}) → HttpCacheEntry? -
Stores
response(with its rawbody) torequest, if storable.requestTimeis when the request was forwarded,responseTimewhen the response head arrived. Returns the new entry, ornull. -
toString(
) → String -
A string representation of this object.
inherited
-
whyNotStorable(
HttpRequestHead request, HttpResponseHead response, {required int bodyBytes, DateTime? responseTime}) → String? -
Why
responsetorequestmay not be stored, ornullwhen it may.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
isRepresentationField(
String name) → bool -
Whether
namedescribes (or frames) the stored body rather than the response as a whole: everyContent-*field exceptContent-Location, plusTransfer-EncodingandTrailer. A304never updates these. -
keyFor(
HttpRequestHead request) → String -
The primary key for
request: lower-casedHost+ request target.HEADandGETshare keys so aHEADcan be answered from aGET.