public RecordingMethodManager(IExecutionCache executionCache, IThreadIdProvider threadProvider, IExecutionStack executionStack, ISerializationHelper serializationHelper) { _executionCache = executionCache; _threadProvider = threadProvider; _executionStack = executionStack; _serializationHelper = serializationHelper; }
public ExecutionCachedSource(BitFlyerClient client, IExecutionCache cache, BfProductCode productCode, int before) { _client = client; _productCode = productCode; _cache = cache; Debug.WriteLine($"{nameof(ExecutionCachedSource)} constructed Before={before}"); var manageRecords = _cache.GetManageTable(); _source = (manageRecords.Count == 0) ? CreateSimpleCopySource(before, 0) : CreateMergedSource(manageRecords, before); }
public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { return(inputs.AsParallel().Select(x => { context.Trace.Verbose("Processing Markdown for {0}", x.Source); string result; IExecutionCache executionCache = context.ExecutionCache; if (!executionCache.TryGetValue <string>(x, out result)) { result = CommonMark.CommonMarkConverter.Convert(x.Content); executionCache.Set(x, result); } return x.Clone(result); })); }
public IRazorPage CreateInstance([NotNull] string relativePath, Stream stream) { if (relativePath.StartsWith("~/", StringComparison.Ordinal)) { // For tilde slash paths, drop the leading ~ to make it work with the underlying IFileProvider. relativePath = relativePath.Substring(1); } // Code below is taken from CompilerCache (specifically OnCacheMiss) which is responsible for managing the compilation step in MVC // Check the file var fileProvider = stream == null ? (IFileProvider)_fileProvider : new WyamStreamFileProvider(_fileProvider, stream); var fileInfo = fileProvider.GetFileInfo(relativePath); if (!fileInfo.Exists) { return(null); } // If relative path is the root, it probably means this isn't from reading a file so don't bother with caching IExecutionCache cache = relativePath == "/" ? null : _executionContext.ExecutionCache; string key = null; Type pageType = null; if (cache != null) { key = relativePath + " " + RazorFileHash.GetHash(fileInfo); if (!cache.TryGetValue(key, out pageType)) { pageType = null; } } // Compile and store in cache if not found if (pageType == null) { var relativeFileInfo = new RelativeFileInfo(fileInfo, relativePath); pageType = _razorcompilationService.Compile(relativeFileInfo); cache?.Set(key, pageType); } // Create an return a new page instance IRazorPage page = (IRazorPage)Activator.CreateInstance(pageType); page.Path = relativePath; return(page); }
/// <inheritdoc /> public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { return(inputs.AsParallel().Select(context, input => { Trace.Verbose( "Processing Markdown {0} for {1}", string.IsNullOrEmpty(_sourceKey) ? string.Empty : ("in" + _sourceKey), input.SourceString()); string result; IExecutionCache executionCache = context.ExecutionCache; if (!executionCache.TryGetValue <string>(input, _sourceKey, out result)) { if (string.IsNullOrEmpty(_sourceKey)) { MarkdownPipeline pipeline = CreatePipeline(); result = Markdig.Markdown.ToHtml(input.Content, pipeline); } else if (input.ContainsKey(_sourceKey)) { MarkdownPipeline pipeline = CreatePipeline(); result = Markdig.Markdown.ToHtml(input.String(_sourceKey) ?? string.Empty, pipeline); } else { // Don't do anything if the key doesn't exist return input; } if (_escapeAt) { result = EscapeAtRegex.Replace(result, "@"); result = result.Replace("\\@", "@"); } executionCache.Set(input, _sourceKey, result); } return string.IsNullOrEmpty(_sourceKey) ? context.GetDocument(input, context.GetContentStream(result)) : context.GetDocument(input, new MetadataItems { { string.IsNullOrEmpty(_destinationKey) ? _sourceKey : _destinationKey, result } }); })); }
public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { return(inputs.AsParallel().Select(input => { Trace.Verbose("Processing Markdown {0}for {1}", string.IsNullOrEmpty(_sourceKey) ? string.Empty : ("in" + _sourceKey), input.SourceString()); string result; IExecutionCache executionCache = context.ExecutionCache; if (!executionCache.TryGetValue <string>(input, _sourceKey, out result)) { if (string.IsNullOrEmpty(_sourceKey)) { result = CommonMark.CommonMarkConverter.Convert(input.Content); } else { if (!input.ContainsKey(_sourceKey)) { // Don't do anything if the key doesn't exist return input; } result = CommonMark.CommonMarkConverter.Convert(input.String(_sourceKey) ?? string.Empty); } if (_escapeAt) { result = result.Replace("@", "@"); } executionCache.Set(input, _sourceKey, result); } return string.IsNullOrEmpty(_sourceKey) ? context.GetDocument(input, result) : context.GetDocument(input, new MetadataItems { { string.IsNullOrEmpty(_destinationKey) ? _sourceKey : _destinationKey, result } }); })); }
public LessCache(IExecutionCache cache) { _cache = cache; }
/// <inheritdoc /> public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { return(inputs.AsParallel().Select(context, input => { Trace.Verbose( "Processing Markdown {0} for {1}", string.IsNullOrEmpty(_sourceKey) ? string.Empty : ("in" + _sourceKey), input.SourceString()); string result; IExecutionCache executionCache = context.ExecutionCache; if (!executionCache.TryGetValue <string>(input, _sourceKey, out result)) { string content; if (string.IsNullOrEmpty(_sourceKey)) { content = input.Content; } else if (input.ContainsKey(_sourceKey)) { content = input.String(_sourceKey) ?? string.Empty; } else { // Don't do anything if the key doesn't exist return input; } MarkdownPipeline pipeline = CreatePipeline(); using (StringWriter writer = new StringWriter()) { HtmlRenderer htmlRenderer = new HtmlRenderer(writer); pipeline.Setup(htmlRenderer); if (_prependLinkRoot && context.Settings.ContainsKey(Keys.LinkRoot)) { htmlRenderer.LinkRewriter = (link) => { if (link == null || link.Length == 0) { return link; } if (link[0] == '/') { // root-based url, must be rewritten by prepending the LinkRoot setting value // ex: '/virtual/directory' + '/relative/abs/link.html' => '/virtual/directory/relative/abs/link.html' link = context.Settings[Keys.LinkRoot] + link; } return link; }; } MarkdownDocument document = MarkdownParser.Parse(content, pipeline); htmlRenderer.Render(document); writer.Flush(); result = writer.ToString(); } if (_escapeAt) { result = EscapeAtRegex.Replace(result, "@"); result = result.Replace("\\@", "@"); } executionCache.Set(input, _sourceKey, result); } return string.IsNullOrEmpty(_sourceKey) ? context.GetDocument(input, context.GetContentStream(result)) : context.GetDocument(input, new MetadataItems { { string.IsNullOrEmpty(_destinationKey) ? _sourceKey : _destinationKey, result } }); })); }