RequestDetails class

Meta-information a Source will use to return the desired data.

RequestDetails instances are extremely central to pkg:data_layer, as local sources use their unique cacheKey value to decide whether they have relevant information for a given request.

Note that the following code represents implementation details for sources and is hidden from end developers by the simpler API found on the Repository class. But, it is still demonstrative.

final localSource = LocalMemorySource<T>();

await localSource.setItems(
  WriteListOperation<T>(
    items: [MyClass('a'), MyClass('b')],
    details: RequestDetails.write(
      filter: ActiveItemsFilter(),
    ),
  ),
);

final items = await localSource.getItems(
  ReadByIdsOperation<T>(
    operationId: Uuid.v7(),
    details: RequestDetails.read(
      filter: ActiveItemsFilter(),
    ),
  ),
);

// `items` will contain both 'a' and 'b' because the two RequestDetails
// instances will produce matching cacheKeys.
// `items = [MyClass('a'), MyClass('b')]`

final someMoreItems = localSource.getItems(
  ReadByIdsOperation<T>(
    operationId: Uuid.v7(),
    details: RequestDetails(),
  ),
);

// Unless other operations have also taken place, `someMoreItems` will be
// an empty list, because the `LocalSource` has never received a write
// operation with a `RequestDetails` which produced the same `cacheKey` as
// that which is produced by the empty `RequestDetails()` instance.

Constructors

RequestDetails({Filter? filter, bool forceInsert = false, RequestType requestType = defaultRequestType, Pagination? pagination, bool shouldRetry = true, Duration? ttl})
Meta-information a Source will use to return the desired data.
RequestDetails.fromJson(Json data)
Serializes this request information to send to the server.
factory
RequestDetails.read({RequestType requestType = defaultRequestType, Filter? filter, Pagination? pagination, bool shouldRetry = true})
Read-friendly constructor for RequestDetails.
factory
RequestDetails.write({RequestType requestType = defaultRequestType, bool shouldRetry = true, bool forceInsert = false, Pagination? pagination, Duration? ttl})
Write-friendly constructor for RequestDetails. Write RequestDetails surprisingly contain pagination details for the purposes of write-through caches.
factory

Properties

cacheKey CacheKey
Collapses this request into a key suitable for local memory caching. This key should incorporate everything about this request EXCEPT the requestType, as that would create false-positive variance.
latefinal
empty RequestDetails
Copy of this RequestDetails without any filters, pagination, or other do-dads which would segment up a data set. This is used for saving the global list alongside any sliced / filtered lists.
no setter
filter Filter?
Optional Filter for this request.
final
forceInsert bool
Tells sources, especially remote sources, to insert this data even though it may already have an Id. This can be paired with CreationBindings which assign Ids on the client.
final
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
True if filter AND pagination are empty.
no setter
isLocal bool
True if this request would rather return empty data than go off-device.
no setter
isNotEmpty bool
True if filter OR pagination are not empty.
no setter
isRemote bool
True if this request will attempt to go off-device.
no setter
noPaginationCacheKey CacheKey
Cache-key without any pagination, used to group up paginated requests together in a LocalSource's cache.
latefinal
pagination Pagination?
Pagination details for this data request.
final
props List<Object?>
The list of properties that will be used to determine whether two instances are equal.
no setter
requestType RequestType
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shouldRetry bool
True if this request should be retried according to a RetryPolicy. Note that this does not guarantee retries; it merely means the Operation is opted-in to the chance at a retry, according to policy.
final
stringify bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
ttl Duration?
Duration after which cached data should be considered stale. Supplying a non-null value to this can force cache misses from local sources which contain data that is older than this duration.
final

Methods

assertEmpty(String functionName) → void
Asserts that this instane isEmpty. The lone string parameter is useful for easily seeing where this assertion was called.
getCacheKeyInputs() String
Used to assemble all the inputs to this object's full cache key.
getNoPaginationCacheKeyInputs() String
Used to assemble all the inputs to this object's no-pagination cache key.
localCopy() RequestDetails
Equivalent RequestDetails but for the removal of a global or refresh RequestType.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Json
Serializes this request information to send to the server.
toString() String
A string representation of this object.

Operators

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

Constants

defaultPagination → const Pagination
Default Pagination details.
defaultRequestType → const RequestType
Default RequestType.