77
88namespace Nerdbank . GitVersioning . ManagedGit
99{
10- internal class GitPackMemoryCache : GitPackCache
10+ /// <summary>
11+ /// <para>
12+ /// The <see cref="GitPackMemoryCache"/> implements the <see cref="GitPackCache"/> abstract class.
13+ /// When a <see cref="Stream"/> is added to the <see cref="GitPackMemoryCache"/>, it is wrapped in a
14+ /// <see cref="GitPackMemoryCacheStream"/>. This stream allows for just-in-time, random, read-only
15+ /// access to the underlying data (which may deltafied and/or compressed).
16+ /// </para>
17+ /// <para>
18+ /// Whenever data is read from a <see cref="GitPackMemoryCacheStream"/>, the call is forwarded to the
19+ /// underlying <see cref="Stream"/> and cached in a <see cref="MemoryStream"/>. If the same data is read
20+ /// twice, it is read from the <see cref="MemoryStream"/>, rather than the underlying <see cref="Stream"/>.
21+ /// </para>
22+ /// <para>
23+ /// <see cref="Add(long, Stream)"/> and <see cref="TryOpen(long, out Stream?)"/> return <see cref="Stream"/>
24+ /// objects which may operate on the same underlying <see cref="Stream"/>, but independently maintain
25+ /// their state.
26+ /// </para>
27+ /// </summary>
28+ public class GitPackMemoryCache : GitPackCache
1129 {
1230 private readonly Dictionary < long , GitPackMemoryCacheStream > cache = new Dictionary < long , GitPackMemoryCacheStream > ( ) ;
1331
32+ /// <inheritdoc/>
1433 public override Stream Add ( long offset , Stream stream )
1534 {
1635 var cacheStream = new GitPackMemoryCacheStream ( stream ) ;
1736 this . cache . Add ( offset , cacheStream ) ;
1837 return new GitPackMemoryCacheViewStream ( cacheStream ) ;
1938 }
2039
40+ /// <inheritdoc/>
2141 public override bool TryOpen ( long offset , [ NotNullWhen ( true ) ] out Stream ? stream )
2242 {
2343 if ( this . cache . TryGetValue ( offset , out GitPackMemoryCacheStream ? cacheStream ) )
@@ -30,6 +50,7 @@ public override bool TryOpen(long offset, [NotNullWhen(true)] out Stream? stream
3050 return false ;
3151 }
3252
53+ /// <inheritdoc/>
3354 public override void GetCacheStatistics ( StringBuilder builder )
3455 {
3556 builder . AppendLine ( $ "{ this . cache . Count } items in cache") ;
0 commit comments