Microsoft .NET 7 Preview 4 brings Regex improvements, cache metrics

[ad_1]

Microsoft’s latest preview of .NET 7, the forthcoming next version of its software development platform, features enhancements for working with regular expressions and caching.

Downloadable from the Microsoft .NET website, the fourth preview of .NET 7 was published May 10. The production release is due in November.

Microsoft .NET Preview 4 adds remaining planned APIs that add support for span types to the Regex (regular expressions) library. The changes add support for matching with ReadOnlySpan<char> inputs and overhaul the handling of RegexOptions.IgnoreCase. The new span-based APIs include:

  • Regex.IsMatch(ReadOnlySpan<char> input), which indicates whether the regular expression finds a match in the input span.
  • Regex.Count(ReadOnlySpan<char> input), which searches an input string for all occurrences of a regular expression and returns the number of matches.
  • Regex.EnumerateMatches(ReadOnlySpan<char> input), which searches an input span for occurrences of a regular expression and returns a ValueMatchEnumerator to lazily iterate over the matches.

In other Regex improvements, Microsoft said it has worked to make the code generated by the Regex source generator more readable and easier to debug, and to enable projects with multiple source-generated regular expression patterns to share common code.

Preview 4 also introduces metrics support for IMemoryCache. The main APIs being added are MemoryCacheStatistics, which holds cache hit, miss, estimated size, and count for IMemoryCache, and GetCurrentStatistics, which returns an instance of MemoryCacheStatistics, or null when the TrackStatistics flag is not enabled.

Also in Preview 4, Microsoft has finished annotating the Microsoft.Extensions.* libraries for nullability, introduced an Activity.Current change event to enhance OpenTelemetry support for observability, and added the System.Formats.Tar assembly, which contains cross-platform APIs for reading, archiving, writing, and extracting Tar archives.

Microsoft .NET 7 Preview 1 was released February 17, followed by .NET 7 Preview 2 and .NET 7 Preview 3 on March 14 and April 13, respectively.

Copyright © 2022 IDG Communications, Inc.

[ad_2]

Source link