public MemoryCacheBenchmark() { var current = new DirectoryInfo(AppContext.BaseDirectory); while (current != null && !File.Exists(Path.Combine(current.FullName, "taghelpers.json"))) { current = current.Parent; } var tagHelperFilePath = Path.Combine(current.FullName, "taghelpers.json"); var tagHelperBuffer = File.ReadAllBytes(tagHelperFilePath); // Deserialize from json file. var serializer = new JsonSerializer(); serializer.Converters.Add(new TagHelperDescriptorJsonConverter()); using (var stream = new MemoryStream(tagHelperBuffer)) using (var reader = new JsonTextReader(new StreamReader(stream))) { TagHelpers = serializer.Deserialize <IReadOnlyList <TagHelperDescriptor> >(reader); TagHelperHashes = TagHelpers.Select(th => th.GetHashCode()).ToList(); } // Set cache size to 400 so anything more then that will force compacts Cache = new MemoryCache <int, TagHelperDescriptor>(400); }
public override void FormatNode(IntermediateNodeFormatter formatter) { formatter.WriteContent(TagName); formatter.WriteProperty(nameof(TagHelpers), string.Join(", ", TagHelpers.Select(t => t.DisplayName))); formatter.WriteProperty(nameof(TagMode), TagMode.ToString()); formatter.WriteProperty(nameof(TagName), TagName); }