listKeys method

Future<KeyListResult> listKeys({
  1. String? pattern,
  2. String? next,
})

Gets the list of keys in your app cache storage. If pattern is specified, it runs the pattern match to narrow down returned results, otherwise, returns all keys contained in your app's cache storage. See below examples how to specify filtering pattern:

  • h?llo matches hello, hallo and hxllo
  • h*llo matches hllo and heeeello
  • haello matches hello and hallo, but not hillo
  • h^ello matches hallo, hbllo, ... but not hello
  • ha-bllo matches hallo and hbllo

You can paginate through your cache keys using the next cursor. In your first call to listKeys, specify the next value as null. This will start pagination of your cache keys. In the return result of the method you can get the list of keys matching your pattern and also the next value that you can use in your next call to listKeys method to move to the next page. If the returned next value is null this means that you have paginated all your keys and there is no additional keys to paginate.

If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

pattern The pattern string that will be used to filter cache keys

next The next page position cursor to paginate to the next page. If set as null, starts the pagination from the beginning.

Returns the array of matching keys, their values and the next cursor if there are remaining items to paginate.

Implementation

Future<KeyListResult> listKeys({String? pattern, String? next}) async {
  var res = await _fetcher.post<Map<String, dynamic>>(
      '/_api/rest/v1/cache/list-keys',
      body: {'pattern': pattern, 'next': next});

  if (res.errors != null) {
    return KeyListResult(errors: res.errors);
  } else {
    return KeyListResult(
        data: ((res.data!)['data'] as List)
            .cast<Map<dynamic, dynamic>>()
            .map((e) => e.cast<String, dynamic>())
            .toList(),
        next: (res.data!)['next'] as String?);
  }
}