11using System ;
2+ using System . Collections . Generic ;
23using JetBrains . Annotations ;
34using PatchKit . Api ;
45using PatchKit . Api . Models . Main ;
@@ -17,6 +18,9 @@ public class RemoteMetaData : IRemoteMetaData
1718 private readonly MainApiConnection _mainApiConnection ;
1819 private readonly KeysApiConnection _keysApiConnection ;
1920
21+ public Dictionary < int , AppContentSummary > _cacheAppContentSummary = new Dictionary < int , AppContentSummary > ( ) ;
22+ public Dictionary < int , AppDiffSummary > _cacheAppDiffSummary = new Dictionary < int , AppDiffSummary > ( ) ;
23+
2024 public RemoteMetaData ( [ NotNull ] string appSecret , [ NotNull ] IRequestTimeoutCalculator requestTimeoutCalculator )
2125 {
2226 if ( string . IsNullOrEmpty ( appSecret ) )
@@ -77,16 +81,33 @@ public AppContentSummary GetContentSummary(int versionId, CancellationToken canc
7781 {
7882 Checks . ArgumentValidVersionId ( versionId , "versionId" ) ;
7983 DebugLogger . Log ( string . Format ( "Getting content summary of version with id {0}." , versionId ) ) ;
84+ AppContentSummary appContentSummary ;
85+ if ( _cacheAppContentSummary . TryGetValue ( versionId , out appContentSummary ) )
86+ {
87+ return appContentSummary ;
88+ }
8089
81- return _mainApiConnection . GetAppVersionContentSummary ( _appSecret , versionId , cancellationToken ) ;
90+ appContentSummary =
91+ _mainApiConnection . GetAppVersionContentSummary ( _appSecret , versionId , cancellationToken ) ;
92+ _cacheAppContentSummary . Add ( versionId , appContentSummary ) ;
93+ return appContentSummary ;
8294 }
8395
8496 public AppDiffSummary GetDiffSummary ( int versionId , CancellationToken cancellationToken )
8597 {
8698 Checks . ArgumentValidVersionId ( versionId , "versionId" ) ;
8799 DebugLogger . Log ( string . Format ( "Getting diff summary of version with id {0}." , versionId ) ) ;
88100
89- return _mainApiConnection . GetAppVersionDiffSummary ( _appSecret , versionId , cancellationToken ) ;
101+ AppDiffSummary appDiffSummary ;
102+ if ( _cacheAppDiffSummary . TryGetValue ( versionId , out appDiffSummary ) )
103+ {
104+ return appDiffSummary ;
105+ }
106+
107+ appDiffSummary =
108+ _mainApiConnection . GetAppVersionDiffSummary ( _appSecret , versionId , cancellationToken ) ;
109+ _cacheAppDiffSummary . Add ( versionId , appDiffSummary ) ;
110+ return appDiffSummary ;
90111 }
91112
92113 public string GetKeySecret ( string key , string cachedKeySecret , CancellationToken cancellationToken )
0 commit comments