invalidateCache method

void invalidateCache({
  1. required String uri,
  2. required REQUEST_METHODS method,
  3. Object? body,
})

Invalidates a specific cached response.

  • uri: The URI path of the request to invalidate
  • method: The HTTP method of the request to invalidate
  • body: The body of the request to invalidate (for POST/PUT requests)

This removes a specific entry from the cache, requiring a fresh network request for subsequent calls with the same parameters.

Implementation

void invalidateCache({
  required String uri,
  required REQUEST_METHODS method,
  Object? body,
}) {
  final fullUrl = Uri.parse('$baseUrl$uri');

  final key = _keyGenerator.generateKey(
    method: method,
    url: fullUrl,
    body: body,
  );

  _cache.remove(key);
}