@@ -261,6 +261,10 @@ following methods::
261
261
// you can get individual info too
262
262
$startTime = $response->getInfo('start_time');
263
263
264
+ .. tip ::
265
+
266
+ Call ``$response->getInfo('debug') `` to get detailed logs about the HTTP transaction.
267
+
264
268
.. _http-client-streaming-responses :
265
269
266
270
Streaming Responses
@@ -312,17 +316,25 @@ When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
312
316
Caching Requests and Responses
313
317
------------------------------
314
318
315
- This component provides a special HTTP client via the
316
- :class: `Symfony\\ Component\\ HttpClient\\ CachingHttpClient ` class to cache
317
- requests and their responses. The actual HTTP caching is implemented using the
318
- :doc: `HttpKernel component </components/http_kernel >`, so make sure it's
319
- installed in your application.
319
+ This component provides a :class: `Symfony\\ Component\\ HttpClient\\ CachingHttpClient `
320
+ decorator that allows caching responses and serving them from the local storage
321
+ for next requests. The implementation leverages the
322
+ :class: `Symfony\\ Component\\ HttpKernel\\ HttpCache\\ HttpCache ` class under the hood
323
+ so that the :doc: `HttpKernel component </components/http_kernel >` needs to be
324
+ installed in your application::
320
325
321
- ..
322
- .. TODO:
323
- .. Show some example of caching requests+responses
324
- ..
325
- ..
326
+ use Symfony\Component\HttpClient\HttpClient;
327
+ use Symfony\Component\HttpClient\CachingHttpClient;
328
+ use Symfony\Component\HttpKernel\HttpCache\Store;
329
+
330
+ $store = new Store('/path/to/cache/storage/');
331
+ $client = HttpClient::create();
332
+ $client = new CachingHttpClient($client, $store);
333
+
334
+ // this won't hit the network if the resource is already in the cache
335
+ $response = $client->request('GET', 'https://example.com/cacheable-resource');
336
+
337
+ ``CachingHttpClient `` accepts a third argument to set the options of the ``HttpCache ``.
326
338
327
339
Scoping Client
328
340
--------------
0 commit comments