You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Changed [psr/simple-cache](https://packagist.org/packages/psr/simple-cache) to [webclient/cache-contract](https://packagist.org/packages/webclient/cache-contract). You can choose [adapter](https://packagist.org/providers/webclient/cache-contract-implementation) or implements `Webclient\Cache\Contract\CacheInterface` interface.
6
+
- Renamed class `Webclient\Extension\Cache\Client` to `Webclient\Extension\Cache\CacheClientDecorator`
Copy file name to clipboardExpand all lines: README.md
+35-5
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,10 @@ Cache extension for PSR-18 HTTP client.
9
9
10
10
# Install
11
11
12
-
Install this package and your favorite [psr-18 implementation](https://packagist.org/providers/psr/http-client-implementation), [psr-17 implementation](https://packagist.org/providers/psr/http-factory-implementation) and [psr-6 implementation](https://packagist.org/providers/psr/simple-cache-implementation).
12
+
Install this package and your favorite [psr-18 implementation](https://packagist.org/providers/psr/http-client-implementation), [psr-17 implementation](https://packagist.org/providers/psr/http-factory-implementation) and [cache implementation](https://packagist.org/providers/webclient/cache-contract-implementation).
13
13
14
14
```bash
15
-
composer require webclient/ext-cache:^1.0
15
+
composer require webclient/ext-cache:^2.0
16
16
```
17
17
18
18
# Using
@@ -24,17 +24,47 @@ use Psr\Http\Client\ClientInterface;
24
24
use Psr\Http\Message\RequestInterface;
25
25
use Psr\Http\Message\ResponseFactoryInterface;
26
26
use Psr\Http\Message\StreamFactoryInterface;
27
-
use Psr\SimpleCache\CacheInterface;
27
+
use Webclient\Cache\Contract\CacheInterface;
28
28
use Webclient\Extension\Cache\Client;
29
+
use Webclient\Extension\Cache\CacheKeyFactory\CacheKeyFactoryInterface;
29
30
30
31
/**
31
32
* @var ClientInterface $client Your PSR-18 HTTP Client
32
-
* @var CacheInterface $cache Your PSR-6 Simple cache
33
33
* @var ResponseFactoryInterface $responseFactory Your PSR-17 response factory
34
34
* @var StreamFactoryInterface $streamFactory Your PSR-17 stream factory
35
+
* @var CacheInterface $cache Your cache adapter
36
+
* @var CacheKeyFactoryInterface|null $cacheKeyFactory key factory for your cache
35
37
*/
36
-
$http = new Client($client, $cache, $responseFactory, $streamFactory, 'unique-string-for-private-caching');
38
+
$http = new CacheClientDecorator(
39
+
$client,
40
+
$responseFactory,
41
+
$streamFactory,
42
+
$cache,
43
+
$cacheKeyFactory,
44
+
'X-Private-Cache-Key-Header', // name of the header in which the private cache key is contained
45
+
4096, // Maximal response size (with header). null for unlimited.
46
+
2147483648 // maximal TTL of cache items
47
+
);
37
48
38
49
/** @var RequestInterface $request */
39
50
$response = $http->sendRequest($request);
51
+
52
+
/** @var RequestInterface $request */
53
+
$response = $http->sendRequest($request);
54
+
55
+
/**
56
+
* For using private cache add header `X-Private-Cache-Key-Header` (or your configured) to request.
57
+
* header `X-Private-Cache-Key-Header` (or your configured) do not be sent to original http-client.
0 commit comments