Skip to content

Commit

Permalink
Cache removed
Browse files Browse the repository at this point in the history
  • Loading branch information
merorafael committed Jun 4, 2017
1 parent 0be1db4 commit a0ac425
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
],
"require": {
"php": ">=5.4.9",
"ext-soap": "*",
"symfony/cache": "~2.8|~3.0|~4.0"
"ext-soap": "*"
},
"require-dev": {
"satooshi/php-coveralls": "~0.6.1",
Expand All @@ -27,7 +26,7 @@
},
"autoload-dev": {
"psr-4": {
"Mero\\Monolog\\": "tests/Mero/Correios"
"Mero\\Correios\\": "tests/Mero/Correios"
}
},
"extra": {
Expand Down
41 changes: 17 additions & 24 deletions src/Mero/Correios/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Mero\Correios\Exception\AddressNotFoundException;
use Mero\Correios\Exception\InvalidZipCodeException;
use Mero\Correios\Model\Address;
use Symfony\Component\Cache\Simple\FilesystemCache;

class Client
{
Expand Down Expand Up @@ -38,32 +37,26 @@ public function findAddressByZipCode($zipCode)
throw new InvalidZipCodeException('The brazilian zip code should have exacly 8 characters.');
}

$cache = new FilesystemCache();
if (!$cache->has("mero_correios.{$zipCode}")) {
try {
$wsdlConnection = $this->createWsdlConnection();
$address = $wsdlConnection->__soapCall('consultaCEP', [
'consultaCEP' => [
'cep' => $zipCode
]
]);
try {
$wsdlConnection = $this->createWsdlConnection();
$address = $wsdlConnection->__soapCall('consultaCEP', [
'consultaCEP' => [
'cep' => $zipCode
]
]);

$address = new Address(
$address->return->end,
$address->return->bairro,
$address->return->cidade,
$address->return->uf,
$address->return->cep
);
$cache->set("mero_correios.{$zipCode}", $address);
$address = new Address(
$address->return->end,
$address->return->bairro,
$address->return->cidade,
$address->return->uf,
$address->return->cep
);

return $address;
} catch (\SoapFault $e) {
throw new AddressNotFoundException($e->getMessage());
}
return $address;
} catch (\SoapFault $e) {
throw new AddressNotFoundException($e->getMessage());
}

return $cache->get("mero_correios.{$zipCode}");
}

/**
Expand Down

0 comments on commit a0ac425

Please sign in to comment.