Skip to content
This repository was archived by the owner on Sep 6, 2019. It is now read-only.

Commit 2b370fa

Browse files
author
pulkit
committed
removed cache not working with guzzle 5 properly
1 parent 41d7647 commit 2b370fa

File tree

5 files changed

+8
-80
lines changed

5 files changed

+8
-80
lines changed

README.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,31 @@ use GuzzleHttp\Client as GuzzleClient;
5757
$requester = new Requester(new GuzzleClient());
5858

5959
// simple get request
60-
$requester->url('github.com')->get();
60+
$requester->url('example.com')->get();
6161
```
6262

6363
Altering the default retry behaviour
6464
```php
65-
// retry 10 times, with a 1 second wait on a 404 error
66-
$requester->url('github.com')->retry(10)->every(1000)->on([404])->get();
65+
// retry 10 times, with a 1 second wait on a 503 error
66+
$requester->url('example.com')->retry(10)->every(1000)->on([503])->get();
6767

6868
// disabling retry
69-
$requester->url('github.com')->retry(false)->get();
69+
$requester->url('example.com')->retry(false)->get();
7070
```
7171

7272
Disabling ssl check
7373
```php
7474
// ssl check disabled
75-
$requester->url('github.com')->veify(false)->get();
75+
$requester->url('example.com')->veify(false)->get();
7676
```
7777

7878
Use http instead of https
7979
```php
8080
// disable https and use http
81-
$requester->url('github.com')->secure(false)->get();
81+
$requester->url('example.com')->secure(false)->get();
8282

8383
// use http
84-
$requester->url('http://github.com')->get();
85-
```
86-
87-
Caching
88-
```php
89-
$response = $requester->url('github.com')->cache(true)->get();
90-
91-
// Same request should return 304 response
92-
$response = $requester->url('github.com')->cache(true)->get();
84+
$requester->url('http://example.com')->get();
9385
```
9486

9587
Create a Post request

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"php": ">=5.4.0",
1414
"guzzlehttp/guzzle": "5.*",
1515
"guzzlehttp/retry-subscriber": "2.*",
16-
"guzzlehttp/cache-subscriber": "0.*",
1716
"illuminate/support": "~4|~5"
1817
},
1918
"require-dev": {

src/Requester.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use GuzzleHttp\Client as GuzzleClient;
66
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;
7-
use GuzzleHttp\Subscriber\Cache\CacheSubscriber;
87
use PulkitJalan\Requester\Exceptions\InvalidUrlException;
98

109
class Requester
@@ -62,13 +61,6 @@ class Requester
6261
*/
6362
protected $retry = 5;
6463

65-
/**
66-
* Use cache subscriber
67-
*
68-
* @var boolean
69-
*/
70-
protected $cache = false;
71-
7264
/**
7365
* @param \GuzzleHttp\Client $guzzleClient
7466
* @param array $config
@@ -94,10 +86,6 @@ public function getGuzzleClient()
9486
$guzzle = $this->addRetrySubscriber($guzzle);
9587
}
9688

97-
if ($this->cache) {
98-
$guzzle = $this->addCacheSubscriber($guzzle);
99-
}
100-
10189
return $guzzle;
10290
}
10391

@@ -192,19 +180,6 @@ public function on(array $retryOn)
192180
return $this;
193181
}
194182

195-
/**
196-
* Enable or disable the cache subscriber
197-
*
198-
* @param boolean $cache
199-
* @return \PulkitJalan\Requester\Requester
200-
*/
201-
public function cache($cache)
202-
{
203-
$this->cache = $cache;
204-
205-
return $this;
206-
}
207-
208183
/**
209184
* Add a file to the request
210185
*
@@ -364,19 +339,6 @@ protected function addRetrySubscriber(GuzzleClient $guzzle)
364339
return $guzzle;
365340
}
366341

367-
/**
368-
* Add the cache subscriber to the guzzle client
369-
*
370-
* @param \GuzzleHttp\Client $guzzle
371-
* @return \GuzzleHttp\Client
372-
*/
373-
protected function addCacheSubscriber(GuzzleClient $guzzle)
374-
{
375-
CacheSubscriber::attach($guzzle);
376-
377-
return $guzzle;
378-
}
379-
380342
/**
381343
* Get the protocol
382344
*
@@ -401,7 +363,6 @@ protected function initialize()
401363
$this->retryOn = array_get($this->config, 'retry.on', [500, 502, 503, 504]);
402364
$this->retryDelay = array_get($this->config, 'retry.delay', 10);
403365
$this->retry = array_get($this->config, 'retry.times', 5);
404-
$this->cache = array_get($this->config, 'cache', false);
405366
$this->verify(array_get($this->config, 'verify', true));
406367
}
407368
}

src/config/config.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@
6262
|
6363
*/
6464
'on' => [500, 502, 503, 504],
65-
],
66-
67-
/*
68-
|--------------------------------------------------------------------------
69-
| Enable or disable request caching
70-
|--------------------------------------------------------------------------
71-
|
72-
| Uses the guzzle cache subscriber
73-
| https://github.com/guzzle/cache-subscriber
74-
|
75-
*/
76-
'cache' => false
65+
]
7766

7867
];

tests/RequesterTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,6 @@ public function test_changing_retry_options()
113113
$this->assertEquals(false, $this->readAttribute($this->requester, 'retry'));
114114
}
115115

116-
public function test_changing_cache_options()
117-
{
118-
$this->requester->cache(true);
119-
120-
$this->assertEquals(true, $this->readAttribute($this->requester, 'cache'));
121-
122-
$this->guzzle->shouldReceive('get')->once()->with('https://example.com', [
123-
'verify' => true,
124-
]);
125-
126-
$this->requester->url('example.com')->cache(true)->get();
127-
}
128-
129116
public function test_sending_get_request()
130117
{
131118
$this->guzzle->shouldReceive('get')->once()->with('https://example.com', [

0 commit comments

Comments
 (0)