@@ -35,8 +35,10 @@ public WebStringCache(IDatabase redis, IHttpClientFactory httpClientFactory, ILo
3535 /// <param name="url">The URL to fetch.</param>
3636 /// <param name="accepts"> The type of content to accept (e.g., "text/html", "application/json").</param>
3737 /// <param name="cancelToken">The cancellation token.</param>
38+ /// <param name="logger">An optional logger to log the results to.</param>
39+ /// <param name="maxSizeInBytes">The maximum size of the resource to fetch
3840 /// <returns>The resource at the given URL.</returns>
39- public async Task < string ? > Get ( Uri url , IEnumerable < string > accepts , CancellationToken cancelToken , int maxSizeInBytes = defaultMaxSizeInBytes )
41+ public async Task < string ? > Get ( Uri url , IEnumerable < string > accepts , ILogger ? logger , CancellationToken cancelToken , int maxSizeInBytes = defaultMaxSizeInBytes )
4042 {
4143 var cacheKey = GetCacheKey ( url , accepts ) ;
4244 var cached = await redis . StringGetAsync ( cacheKey ) ;
@@ -46,7 +48,7 @@ public WebStringCache(IDatabase redis, IHttpClientFactory httpClientFactory, ILo
4648 }
4749
4850 // It's not in the cache. Fetch it and if fetch was successful, put it in the cache.
49- var webString = await TryGetResource ( url , accepts , cancelToken ) ;
51+ var webString = await TryGetResource ( url , accepts , maxSizeInBytes , logger ?? this . logger , cancelToken ) ;
5052 if ( webString != null )
5153 {
5254 await redis . StringSetAsync ( cacheKey , webString , cacheExpiration ) ;
@@ -55,11 +57,11 @@ public WebStringCache(IDatabase redis, IHttpClientFactory httpClientFactory, ILo
5557 return webString ;
5658 }
5759
58- private async Task < string ? > TryGetResource ( Uri appUrl , IEnumerable < string > accepts , CancellationToken cancelToken )
60+ private async Task < string ? > TryGetResource ( Uri appUrl , IEnumerable < string > accepts , int maxSizeInBytes , ILogger logger , CancellationToken cancelToken )
5961 {
6062 try
6163 {
62- var webString = await http . GetStringAsync ( appUrl , accepts , defaultMaxSizeInBytes , cancelToken ) ;
64+ var webString = await http . GetStringAsync ( appUrl , accepts , maxSizeInBytes , cancelToken ) ;
6365 if ( webString == null )
6466 {
6567 logger . LogWarning ( "No response received for {appUrl} with accept {accept}." , appUrl , accepts ) ;
0 commit comments