Skip to content

Commit

Permalink
version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ddrv committed Jul 26, 2022
1 parent 101f795 commit 0179dba
Show file tree
Hide file tree
Showing 16 changed files with 1,742 additions and 678 deletions.
3 changes: 2 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
custom: "https://www.paypal.me/ddrv"
custom: "https://www.paypal.me/ddrv"
patreon: ddrv
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
php: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0]
php: [7.4, 8.0, 8.1]

steps:
- name: Checkout code
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

## Version 2.0.0

- 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.
- Renamed class `Webclient\Extension\Cache\Client` to `Webclient\Extension\Cache\CacheClientDecorator`
- Added tests
- Fixed caching
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Cache extension for PSR-18 HTTP client.

# Install

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

```bash
composer require webclient/ext-cache:^1.0
composer require webclient/ext-cache:^2.0
```

# Using
Expand All @@ -24,17 +24,47 @@ use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\SimpleCache\CacheInterface;
use Webclient\Cache\Contract\CacheInterface;
use Webclient\Extension\Cache\Client;
use Webclient\Extension\Cache\CacheKeyFactory\CacheKeyFactoryInterface;

/**
* @var ClientInterface $client Your PSR-18 HTTP Client
* @var CacheInterface $cache Your PSR-6 Simple cache
* @var ResponseFactoryInterface $responseFactory Your PSR-17 response factory
* @var StreamFactoryInterface $streamFactory Your PSR-17 stream factory
* @var CacheInterface $cache Your cache adapter
* @var CacheKeyFactoryInterface|null $cacheKeyFactory key factory for your cache
*/
$http = new Client($client, $cache, $responseFactory, $streamFactory, 'unique-string-for-private-caching');
$http = new CacheClientDecorator(
$client,
$responseFactory,
$streamFactory,
$cache,
$cacheKeyFactory,
'X-Private-Cache-Key-Header', // name of the header in which the private cache key is contained
4096, // Maximal response size (with header). null for unlimited.
2147483648 // maximal TTL of cache items
);

/** @var RequestInterface $request */
$response = $http->sendRequest($request);

/** @var RequestInterface $request */
$response = $http->sendRequest($request);

/**
* For using private cache add header `X-Private-Cache-Key-Header` (or your configured) to request.
* header `X-Private-Cache-Key-Header` (or your configured) do not be sent to original http-client.
*/
$response = $http->sendRequest($request->withHeader('X-Private-Cache-Key-Header', ['private-key-for-current-user']));

```

## Not handled requests

If the request contains `If-None-Match`, `If-Match`, `If-Modified-Since`, `If-Unmodified-Since`, or `If-Range` headers,
then the response will be returned as is.

## Partial Requests

Partial requests not supports.
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
}
],
"require": {
"php": ">=7.0",
"php": "^7.4 || ^8.0",
"ext-json": "*",
"ext-mbstring": "*",
"psr/http-client": "^1.0",
"psr/simple-cache": "^1.0",
"psr/http-factory": "^1.0"
"psr/http-factory": "^1.0",
"webclient/cache-contract": "^1.0"
},
"require-dev": {
"guzzlehttp/psr7": "^1.7",
"phpunit/phpunit": ">=6.5",
"squizlabs/php_codesniffer": "^3.5",
"webclient/fake-http-client": "^1.0"
"nyholm/psr7": "^1.5",
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.5 || ^9.5",
"squizlabs/php_codesniffer": "^3.7",
"webclient/fake-http-client": "^2.0"
},
"provide": {
"psr/http-client-implementation": "1.0"
},
"suggest": {
"psr/http-client-implementation": "Choice your favorite psr-18 implementation",
"psr/simple-cache-implementation": "Choice your favorite psr-6 implementation"
"webclient/cache-contract-implementation": "Choice your cache implementation"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 0179dba

Please sign in to comment.