Skip to content

Commit 0179dba

Browse files
committed
version 2.0
1 parent 101f795 commit 0179dba

16 files changed

+1742
-678
lines changed

.github/FUNDING.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
custom: "https://www.paypal.me/ddrv"
1+
custom: "https://www.paypal.me/ddrv"
2+
patreon: ddrv

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0]
11+
php: [7.4, 8.0, 8.1]
1212

1313
steps:
1414
- name: Checkout code

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
## Version 2.0.0
4+
5+
- 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`
7+
- Added tests
8+
- Fixed caching

README.md

+35-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Cache extension for PSR-18 HTTP client.
99

1010
# Install
1111

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).
1313

1414
```bash
15-
composer require webclient/ext-cache:^1.0
15+
composer require webclient/ext-cache:^2.0
1616
```
1717

1818
# Using
@@ -24,17 +24,47 @@ use Psr\Http\Client\ClientInterface;
2424
use Psr\Http\Message\RequestInterface;
2525
use Psr\Http\Message\ResponseFactoryInterface;
2626
use Psr\Http\Message\StreamFactoryInterface;
27-
use Psr\SimpleCache\CacheInterface;
27+
use Webclient\Cache\Contract\CacheInterface;
2828
use Webclient\Extension\Cache\Client;
29+
use Webclient\Extension\Cache\CacheKeyFactory\CacheKeyFactoryInterface;
2930

3031
/**
3132
* @var ClientInterface $client Your PSR-18 HTTP Client
32-
* @var CacheInterface $cache Your PSR-6 Simple cache
3333
* @var ResponseFactoryInterface $responseFactory Your PSR-17 response factory
3434
* @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
3537
*/
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+
);
3748

3849
/** @var RequestInterface $request */
3950
$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.
58+
*/
59+
$response = $http->sendRequest($request->withHeader('X-Private-Cache-Key-Header', ['private-key-for-current-user']));
60+
4061
```
62+
63+
## Not handled requests
64+
65+
If the request contains `If-None-Match`, `If-Match`, `If-Modified-Since`, `If-Unmodified-Since`, or `If-Range` headers,
66+
then the response will be returned as is.
67+
68+
## Partial Requests
69+
70+
Partial requests not supports.

composer.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=7.0",
15+
"php": "^7.4 || ^8.0",
1616
"ext-json": "*",
1717
"ext-mbstring": "*",
1818
"psr/http-client": "^1.0",
19-
"psr/simple-cache": "^1.0",
20-
"psr/http-factory": "^1.0"
19+
"psr/http-factory": "^1.0",
20+
"webclient/cache-contract": "^1.0"
2121
},
2222
"require-dev": {
23-
"guzzlehttp/psr7": "^1.7",
24-
"phpunit/phpunit": ">=6.5",
25-
"squizlabs/php_codesniffer": "^3.5",
26-
"webclient/fake-http-client": "^1.0"
23+
"nyholm/psr7": "^1.5",
24+
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.5 || ^9.5",
25+
"squizlabs/php_codesniffer": "^3.7",
26+
"webclient/fake-http-client": "^2.0"
2727
},
2828
"provide": {
2929
"psr/http-client-implementation": "1.0"
3030
},
3131
"suggest": {
3232
"psr/http-client-implementation": "Choice your favorite psr-18 implementation",
33-
"psr/simple-cache-implementation": "Choice your favorite psr-6 implementation"
33+
"webclient/cache-contract-implementation": "Choice your cache implementation"
3434
},
3535
"autoload": {
3636
"psr-4": {

0 commit comments

Comments
 (0)