WireCacheRecord class

A cached HTTP response stored as raw wire data.

CRITICAL: Cache stores raw response bytes, NOT decoded types. This prevents:

  • Decoder bugs from corrupting cache
  • Type T from fragmenting cache (same URL, different decoders = same entry)
  • Serialization issues with complex types
Annotations

Constructors

WireCacheRecord({required String canonicalKey, required Uint8List bodyBytes, required int statusCode, required Map<String, String> headers, required DateTime cachedAt, DateTime? expiresAt, String? etag, String? lastModified})
const
WireCacheRecord.fromBytes(Uint8List bytes)
Deserialize from bytes.
factory
WireCacheRecord.fromResponse(Response response, String canonicalKey, {Duration? ttl})
Create from a Dio response.
factory

Properties

age Duration
Age of this cache entry.
no setter
bodyBytes Uint8List
Raw response body bytes.
final
bodyData → dynamic
Get body data in appropriate format based on content-type.
no setter
bodyJson → dynamic
Decode the body as JSON.
no setter
bodyJsonOrNull → dynamic
Try to get body as JSON, returning null on parse failure.
no setter
bodyString String
Decode the body as a UTF-8 string.
no setter
cachedAt DateTime
When this was cached.
final
canonicalKey String
The canonical request key this caches.
final
etag String?
ETag for conditional requests.
final
expiresAt DateTime?
When this expires (computed from TTL or Cache-Control).
final
hashCode int
The hash code for this object.
no setterinherited
hasNoCache bool
Check if response should always be revalidated.
no setter
hasNoStore bool
Check if response should never be cached based on headers.
no setter
headers Map<String, String>
Response headers (subset: content-type, etag, last-modified, cache-control).
final
isExpired bool
Check if expired.
no setter
isJsonContent bool
Check if content-type indicates JSON.
no setter
isStale bool
Check if stale (same as expired, but usable for stale-while-revalidate).
no setter
isTextContent bool
Check if content-type indicates plain text.
no setter
lastModified String?
Last-Modified for conditional requests.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sizeBytes int
Size in bytes for cache eviction calculations.
no setter
statusCode int
HTTP status code.
final
timeToLive Duration?
Time until expiry (negative if expired).
no setter

Methods

copyWithExpiry(DateTime? expiresAt) WireCacheRecord
Create a copy with updated expiry.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toBytes() Uint8List
Serialize to bytes for storage.
toString() String
A string representation of this object.
override
touch({Duration? ttl}) WireCacheRecord
Refresh the cached timestamp (for 304 responses).

Operators

operator ==(Object other) bool
The equality operator.
inherited