Skip to content

Commit

Permalink
Disable info provider result caching when in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtronics committed Feb 20, 2025
1 parent e7394c1 commit a596166
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Services/InfoProviderSystem/PartInfoRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;

Expand All @@ -37,7 +38,9 @@ final class PartInfoRetriever
private const CACHE_RESULT_EXPIRATION = 60 * 60 * 24 * 4; // 7 days

public function __construct(private readonly ProviderRegistry $provider_registry,
private readonly DTOtoEntityConverter $dto_to_entity_converter, private readonly CacheInterface $partInfoCache)
private readonly DTOtoEntityConverter $dto_to_entity_converter, private readonly CacheInterface $partInfoCache,
#[Autowire(param: "kernel.debug")]
private readonly bool $debugMode = false)
{
}

Expand Down Expand Up @@ -77,7 +80,7 @@ protected function searchInProvider(InfoProviderInterface $provider, string $key
$escaped_keyword = urlencode($keyword);
return $this->partInfoCache->get("search_{$provider->getProviderKey()}_{$escaped_keyword}", function (ItemInterface $item) use ($provider, $keyword) {
//Set the expiration time
$item->expiresAfter(self::CACHE_RESULT_EXPIRATION);
$item->expiresAfter(!$this->debugMode ? self::CACHE_RESULT_EXPIRATION : 1);

return $provider->searchByKeyword($keyword);
});
Expand All @@ -98,7 +101,7 @@ public function getDetails(string $provider_key, string $part_id): PartDetailDTO
$escaped_part_id = urlencode($part_id);
return $this->partInfoCache->get("details_{$provider_key}_{$escaped_part_id}", function (ItemInterface $item) use ($provider, $part_id) {
//Set the expiration time
$item->expiresAfter(self::CACHE_DETAIL_EXPIRATION);
$item->expiresAfter(!$this->debugMode ? self::CACHE_DETAIL_EXPIRATION : 1);

return $provider->getDetails($part_id);
});
Expand Down

0 comments on commit a596166

Please sign in to comment.