Пример #1
0
        private bool AssociatedGlobalFilesChanged(CompilerCacheEntry entry,
                                                  Func <RelativeFileInfo, CompilationResult> compile)
        {
            var globalFileEntry = GetCompositeGlobalFileEntry(entry.RelativePath, compile);

            return(entry.AssociatedGlobalFileEntry != globalFileEntry);
        }
Пример #2
0
        internal CompilerCache(IEnumerable <RazorFileInfoCollection> razorFileInfoCollections,
                               IAssemblyLoadContext loadContext,
                               IFileProvider fileProvider)
        {
            _fileProvider = fileProvider;
            _cache        = new MemoryCache(new MemoryCacheOptions {
                CompactOnMemoryPressure = false
            });

            var cacheEntries = new List <CompilerCacheEntry>();

            foreach (var viewCollection in razorFileInfoCollections)
            {
                var containingAssembly = viewCollection.LoadAssembly(loadContext);
                foreach (var fileInfo in viewCollection.FileInfos)
                {
                    var viewType   = containingAssembly.GetType(fileInfo.FullTypeName);
                    var cacheEntry = new CompilerCacheEntry(fileInfo, viewType);

                    // There shouldn't be any duplicates and if there are any the first will win.
                    // If the result doesn't match the one on disk its going to recompile anyways.
                    var normalizedPath = NormalizePath(fileInfo.RelativePath);
                    _cache.Set(
                        normalizedPath,
                        cacheEntry,
                        GetMemoryCacheEntryOptions(fileInfo.RelativePath));

                    cacheEntries.Add(cacheEntry);
                }
            }

            // Set up _ViewImports
            foreach (var entry in cacheEntries)
            {
                var globalFileLocations = ViewHierarchyUtility.GetViewImportsLocations(entry.RelativePath);
                foreach (var location in globalFileLocations)
                {
                    var globalFileEntry = _cache.Get <CompilerCacheEntry>(location);
                    if (globalFileEntry != null)
                    {
                        // Add the composite _ViewImports entry as a dependency.
                        entry.AssociatedGlobalFileEntry = globalFileEntry;
                        break;
                    }
                }
            }
        }
Пример #3
0
        internal CompilerCache(IEnumerable<RazorFileInfoCollection> razorFileInfoCollections,
                               IAssemblyLoadContext loadContext,
                               IFileProvider fileProvider)
        {
            _fileProvider = fileProvider;
            _cache = new MemoryCache(new MemoryCacheOptions { CompactOnMemoryPressure = false });

            var cacheEntries = new List<CompilerCacheEntry>();
            foreach (var viewCollection in razorFileInfoCollections)
            {
                var containingAssembly = viewCollection.LoadAssembly(loadContext);
                foreach (var fileInfo in viewCollection.FileInfos)
                {
                    var viewType = containingAssembly.GetType(fileInfo.FullTypeName);
                    var cacheEntry = new CompilerCacheEntry(fileInfo, viewType);

                    // There shouldn't be any duplicates and if there are any the first will win.
                    // If the result doesn't match the one on disk its going to recompile anyways.
                    var normalizedPath = NormalizePath(fileInfo.RelativePath);
                    _cache.Set(
                        normalizedPath,
                        cacheEntry,
                        GetMemoryCacheEntryOptions(fileInfo.RelativePath));

                    cacheEntries.Add(cacheEntry);
                }
            }

            // Set up _ViewImports
            foreach (var entry in cacheEntries)
            {
                var globalFileLocations = ViewHierarchyUtility.GetViewImportsLocations(entry.RelativePath);
                foreach (var location in globalFileLocations)
                {
                    var globalFileEntry = _cache.Get<CompilerCacheEntry>(location);
                    if (globalFileEntry != null)
                    {
                        // Add the composite _ViewImports entry as a dependency.
                        entry.AssociatedGlobalFileEntry = globalFileEntry;
                        break;
                    }
                }
            }
        }
Пример #4
0
        private GetOrAddResult OnCacheMiss(RelativeFileInfo file,
                                           string normalizedPath,
                                           Func <RelativeFileInfo, CompilationResult> compile)
        {
            var compilationResult = compile(file).EnsureSuccessful();

            // Concurrent addition to MemoryCache with the same key result in safe race.
            var compilerCacheEntry = new CompilerCacheEntry(file, compilationResult.CompiledType);
            var cacheEntry         = _cache.Set <CompilerCacheEntry>(
                normalizedPath,
                compilerCacheEntry,
                GetMemoryCacheEntryOptions(compilerCacheEntry.RelativePath));

            return(new GetOrAddResult
            {
                CompilationResult = compilationResult,
                CompilerCacheEntry = cacheEntry
            });
        }
Пример #5
0
 private bool AssociatedGlobalFilesChanged(CompilerCacheEntry entry,
                                           Func<RelativeFileInfo, CompilationResult> compile)
 {
     var globalFileEntry = GetCompositeGlobalFileEntry(entry.RelativePath, compile);
     return entry.AssociatedGlobalFileEntry != globalFileEntry;
 }
Пример #6
0
        private GetOrAddResult OnCacheMiss(RelativeFileInfo file,
                                           string normalizedPath,
                                           Func<RelativeFileInfo, CompilationResult> compile)
        {
            var compilationResult = compile(file).EnsureSuccessful();

            // Concurrent addition to MemoryCache with the same key result in safe race.
            var compilerCacheEntry = new CompilerCacheEntry(file, compilationResult.CompiledType);
            var cacheEntry = _cache.Set<CompilerCacheEntry>(
                normalizedPath,
                compilerCacheEntry,
                GetMemoryCacheEntryOptions(compilerCacheEntry.RelativePath));

            return new GetOrAddResult
            {
                CompilationResult = compilationResult,
                CompilerCacheEntry = cacheEntry
            };
        }