Skip to content

Commit

Permalink
Merge pull request #3 from florianv/cache-refresh
Browse files Browse the repository at this point in the history
Replace option to disable the cache
  • Loading branch information
florianv authored Oct 8, 2016
2 parents 74b9238 + ecb1a0e commit 7be667a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions doc/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ $query = (new ExchangeRateQueryBuilder('JPY/GBP'))
->addOption('cache_ttl', 60)
->build();

// Force refreshing the rate from the service for this query
// Disable caching for this query
$query = (new ExchangeRateQueryBuilder('JPY/GBP'))
->addOption('cache_refresh', true)
->addOption('cache', false)
->build();
```

Expand Down
4 changes: 2 additions & 2 deletions src/Exchanger.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public function getExchangeRate(ExchangeRateQueryContract $exchangeQuery)
throw new UnsupportedExchangeQueryException($exchangeQuery, $this->service);
}

if (null === $this->cacheItemPool) {
if (null === $this->cacheItemPool || false === $exchangeQuery->getOption('cache')) {
return $this->service->getExchangeRate($exchangeQuery);
}

$item = $this->cacheItemPool->getItem(sha1(serialize($exchangeQuery)));

if (!$exchangeQuery->getOption('cache_refresh') && $item->isHit()) {
if ($item->isHit()) {
return $item->get();
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Tests/ExchangerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ public function it_caches_a_rate()
/**
* @test
*/
public function it_does_not_use_cache_if_refresh()
public function it_does_not_use_cache_if_cache_false()
{
$exchangeRateQuery = new ExchangeRateQuery(CurrencyPair::createFromString('EUR/USD'), ['cache_refresh' => true]);
$exchangeRateQuery = new ExchangeRateQuery(CurrencyPair::createFromString('EUR/USD'), ['cache' => false]);

$service = $this->getMock('Exchanger\Contract\ExchangeRateService');

Expand All @@ -251,12 +251,12 @@ public function it_does_not_use_cache_if_refresh()
$pool = $this->getMock('Psr\Cache\CacheItemPoolInterface');

$pool
->expects($this->once())
->expects($this->never())
->method('getItem')
->will($this->returnValue($item));

$pool
->expects($this->once())
->expects($this->never())
->method('save')
->with($item);

Expand Down

0 comments on commit 7be667a

Please sign in to comment.