예제 #1
0
 private void AddRepositoryContentsToCache(RepositoryReference repoSpec, IEnumerable <RepositoryContent> contentList)
 {
     foreach (var repoContent in contentList)
     {
         var subKey = new RepositoryPathReference
         {
             RepositoryOwner = repoSpec.RepositoryOwner,
             RepositoryName  = repoSpec.RepositoryName,
             TreeReference   = repoSpec.TreeReference,
             Path            = repoContent.Path
         };
         if (RepositoryCache.TryGetValue(subKey, out RepositoryContentEntry subEntry))
         {
             subEntry.Leaf = repoContent;
         }
         else
         {
             subEntry = new RepositoryContentEntry {
                 Leaf = repoContent
             }
         };
         var subOptions = new MemoryCacheEntryOptions {
             Size = repoContent.Size
         };
         RepositoryCache.Set(subKey, subEntry, subOptions);
         if (repoContent.Type.TryParse(out var repoContentType) && repoContentType == ContentType.File)
         {
             subEntry.Contents = new List <RepositoryContent>(capacity: 1)
             {
                 repoContent
             }
         }
         ;
     }
 }
예제 #2
0
        private async Task <RepositoryContentEntry> GetRepositoryContentEntry(RepositoryReference repoSpec, string path)
        {
            var entryKey = new RepositoryPathReference
            {
                RepositoryOwner = repoSpec.RepositoryOwner,
                RepositoryName  = repoSpec.RepositoryName,
                TreeReference   = repoSpec.TreeReference,
                Path            = path
            };
            var entryObj = await RepositoryCache.GetOrCreateAsync(
                entryKey, CreateCachedRepositoryContentEntry
                ).ConfigureAwait(continueOnCapturedContext: false);

            if (entryObj.Contents is null)
            {
                var entryContents = await DownloadRepositoryContents(repoSpec, path)
                                    .ConfigureAwait(continueOnCapturedContext: false);

                AddRepositoryContentsToCache(repoSpec, entryContents);
                entryObj.Contents = entryContents;
            }
            return(entryObj);
        }