getFromPath method

  1. @override
Future<List<CacheResponse>> getFromPath(
  1. RegExp pathPattern, {
  2. Map<String, String?>? queryParams,
})

Retrieves cached responses from a path pattern.

pathPattern path pattern (e.g. RegExp('https://www.example.com/a/b') or RegExp(r'https://www.example.com/a/\d+)).

queryParams filter is processed in the following way:

  • null: all entries are collected,
  • null value: all entries containing the key are collected,
  • otherwise key/value match only.

You should be very restrictive when using this method as the underlying store may parse and load all data from the store.

Implementation

@override
Future<List<CacheResponse>> getFromPath(
  RegExp pathPattern, {
  Map<String, String?>? queryParams,
}) async {
  final responses = <CacheResponse>[];

  final box = await _openBox();

  for (var i = 0; i < box.keys.length; i++) {
    final resp = await box.getAt(i);

    if (resp != null) {
      if (pathExists(resp.url, pathPattern, queryParams: queryParams)) {
        responses.add(resp);
      }
    }
  }

  return responses;
}