set method

Future<void> set(
  1. Response response, [
  2. Duration? cacheLifetimeDuration
])

Caches the response data from a request.

Implementation

Future<void> set(Response response, [Duration? cacheLifetimeDuration]) async {
  final cacheKey = _generateCacheKey(response.requestOptions);

  final cacheModel = CacheModel(
    expirationDateTime: DateTime.now()
        .add(cacheLifetimeDuration ?? cacheOptions.cacheLifetimeDuration),
    value: response.data,
  );

  await _storage.set(cacheKey, cacheModel.toMap());
}