Example #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
             }
         }
         ;
     }
 }
Example #2
0
        private async Task <RepositoryContentEntry> CreateCachedRepositoryContentEntry(ICacheEntry entryOptions)
        {
            var    entryKey      = (RepositoryPathReference)entryOptions.Key;
            string entryPath     = entryKey.Path;
            var    entryContents = await DownloadRepositoryContents(entryKey, entryPath)
                                   .ConfigureAwait(continueOnCapturedContext: false);

            AddRepositoryContentsToCache(entryKey, entryContents);

            if (RepositoryCache.TryGetValue(entryKey, out RepositoryContentEntry entryObj))
            {
                entryObj.Contents = entryContents;
            }
            else
            {
                entryObj = new RepositoryContentEntry {
                    Contents = entryContents
                }
            };
            entryOptions.Size = entryObj.Leaf?.Size;

            return(entryObj);
        }