getCachedResponse method

  1. @override
Future<ChatResponse?> getCachedResponse(
  1. String key
)
override

Retrieves a cached response for the given key, or null if not found.

Implementation

@override
Future<ChatResponse?> getCachedResponse(String key) async {
  final stopwatch = Stopwatch()..start();
  final response = await _cache.get(key);
  stopwatch.stop();
  if (response != null) {
    _chatDetails.addTurnDetails(ChatTurnDetails(
      latency: stopwatch.elapsed,
      model: response.modelId,
      usage: response.usage,
      cacheKey: key,
      cacheHit: true,
    ));
  }
  return response;
}