27
27
use App \Services \InfoProviderSystem \DTOs \PartDetailDTO ;
28
28
use App \Services \InfoProviderSystem \DTOs \SearchResultDTO ;
29
29
use App \Services \InfoProviderSystem \Providers \InfoProviderInterface ;
30
+ use Symfony \Component \DependencyInjection \Attribute \Autowire ;
30
31
use Symfony \Contracts \Cache \CacheInterface ;
31
32
use Symfony \Contracts \Cache \ItemInterface ;
32
33
@@ -37,7 +38,9 @@ final class PartInfoRetriever
37
38
private const CACHE_RESULT_EXPIRATION = 60 * 60 * 24 * 4 ; // 7 days
38
39
39
40
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 )
41
44
{
42
45
}
43
46
@@ -77,7 +80,7 @@ protected function searchInProvider(InfoProviderInterface $provider, string $key
77
80
$ escaped_keyword = urlencode ($ keyword );
78
81
return $ this ->partInfoCache ->get ("search_ {$ provider ->getProviderKey ()}_ {$ escaped_keyword }" , function (ItemInterface $ item ) use ($ provider , $ keyword ) {
79
82
//Set the expiration time
80
- $ item ->expiresAfter (self ::CACHE_RESULT_EXPIRATION );
83
+ $ item ->expiresAfter (! $ this -> debugMode ? self ::CACHE_RESULT_EXPIRATION : 1 );
81
84
82
85
return $ provider ->searchByKeyword ($ keyword );
83
86
});
@@ -98,7 +101,7 @@ public function getDetails(string $provider_key, string $part_id): PartDetailDTO
98
101
$ escaped_part_id = urlencode ($ part_id );
99
102
return $ this ->partInfoCache ->get ("details_ {$ provider_key }_ {$ escaped_part_id }" , function (ItemInterface $ item ) use ($ provider , $ part_id ) {
100
103
//Set the expiration time
101
- $ item ->expiresAfter (self ::CACHE_DETAIL_EXPIRATION );
104
+ $ item ->expiresAfter (! $ this -> debugMode ? self ::CACHE_DETAIL_EXPIRATION : 1 );
102
105
103
106
return $ provider ->getDetails ($ part_id );
104
107
});
0 commit comments