Skip to content

Commit a596166

Browse files
committed
Disable info provider result caching when in debug mode
1 parent e7394c1 commit a596166

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Services/InfoProviderSystem/PartInfoRetriever.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
2828
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
2929
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
30+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
3031
use Symfony\Contracts\Cache\CacheInterface;
3132
use Symfony\Contracts\Cache\ItemInterface;
3233

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

3940
public function __construct(private readonly ProviderRegistry $provider_registry,
40-
private readonly DTOtoEntityConverter $dto_to_entity_converter, private readonly CacheInterface $partInfoCache)
41+
private readonly DTOtoEntityConverter $dto_to_entity_converter, private readonly CacheInterface $partInfoCache,
42+
#[Autowire(param: "kernel.debug")]
43+
private readonly bool $debugMode = false)
4144
{
4245
}
4346

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

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

103106
return $provider->getDetails($part_id);
104107
});

0 commit comments

Comments
 (0)