2727use App \Services \InfoProviderSystem \DTOs \PartDetailDTO ;
2828use App \Services \InfoProviderSystem \DTOs \SearchResultDTO ;
2929use App \Services \InfoProviderSystem \Providers \InfoProviderInterface ;
30+ use Symfony \Component \DependencyInjection \Attribute \Autowire ;
3031use Symfony \Contracts \Cache \CacheInterface ;
3132use 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