1
- using System . Net . Http ;
1
+ using System . Collections . Generic ;
2
+ using System . Net . Http ;
2
3
using System . Net . Http . Headers ;
3
4
using System . Threading . Tasks ;
4
5
using Microsoft . Azure . Management . ApiManagement . ArmTemplates . Common ;
5
- using System . Collections . Generic ;
6
6
using Microsoft . Azure . Management . ApiManagement . ArmTemplates . Create ;
7
+ using Microsoft . Extensions . Caching . Memory ;
7
8
8
9
namespace Microsoft . Azure . Management . ApiManagement . ArmTemplates . Extract
9
10
{
10
11
public class EntityExtractor
11
12
{
12
13
public string baseUrl = "https://management.azure.com" ;
13
14
internal Authentication auth = new Authentication ( ) ;
15
+ private static readonly IMemoryCache _cache = new MemoryCache ( new MemoryCacheOptions ( ) ) ;
14
16
15
17
public static async Task < string > CallApiManagementAsync ( string azToken , string requestUrl )
16
18
{
19
+ if ( _cache . TryGetValue ( requestUrl , out string cachedResponseBody ) )
20
+ {
21
+ return cachedResponseBody ;
22
+ }
23
+
17
24
using ( HttpClient httpClient = new HttpClient ( ) )
18
25
{
19
26
var request = new HttpRequestMessage ( HttpMethod . Get , requestUrl ) ;
@@ -24,6 +31,9 @@ public static async Task<string> CallApiManagementAsync(string azToken, string r
24
31
25
32
response . EnsureSuccessStatusCode ( ) ;
26
33
string responseBody = await response . Content . ReadAsStringAsync ( ) ;
34
+
35
+ _cache . Set ( requestUrl , responseBody ) ;
36
+
27
37
return responseBody ;
28
38
}
29
39
}
@@ -58,4 +68,4 @@ public Template GenerateEmptyTemplateWithParameters(string policyXMLBaseUrl, str
58
68
return armTemplate ;
59
69
}
60
70
}
61
- }
71
+ }
0 commit comments