IT资讯 .NET 7 Preview 4 发布

kenny · 2022-05-12 11:30:06 · 热度: 19

.NET 7 发布了第 4 个预览版。

.NET 7 Preview 4 发布

重要变化一览

  • 增强 OpenTelemetry 的 .NET 实现的可观测性
  • 为日期和时间结构体增加微秒和纳秒属性
  • 为缓存扩展(caching extensions)引入新指标
  • 提升“On Stack Replacement”性能
  • 增加新的 tar API
  • 优化 .NET 7 中正则表达式的性能、增加功能

为 TimeStamp、DateTime、DateTimeOffset 和 TimeOnly 添加微秒和纳秒属性

在 Preview 4 之前,各种日期和时间结构体中,可用的最小时间增量是 Ticks 属性中可用的“tick”。在 .NET 中,一个 tick 是 100ns。此前开发者必须对"tick"值执行计算以确定微秒和纳秒值。现在,Preview 4 通过在日期和时间实现中引入微秒和毫秒来解决这个问题。

增加新的 tar API

此版本添加了新的程序集,包含可读取、写入、归档和提取 tar 存档的跨平台 API。

使用示例

// Generates a tar archive where all the entry names are prefixed by the root directory 'SourceDirectory'
TarFile.CreateFromDirectory(sourceDirectoryName: "/home/dotnet/SourceDirectory/", destinationFileName: "/home/dotnet/destination.tar", includeBaseDirectory: true);

// Extracts the contents of a tar archive into the specified directory, but avoids overwriting anything found inside
TarFile.ExtractToDirectory(sourceFileName: "/home/dotnet/destination.tar", destinationDirectoryName: "/home/dotnet/DestinationDirectory/", overwriteFiles: false);
// Generates a tar archive where all the entry names are prefixed by the root directory 'SourceDirectory'
using MemoryStream archiveStream = new();
TarFile.CreateFromDirectory(sourceDirectoryName: @"D:SourceDirectory", destination: archiveStream, includeBaseDirectory: true);

// Extracts the contents of a stream tar archive into the specified directory, and avoids overwriting anything found inside
TarFile.ExtractToDirectory(source: archiveStream, destinationDirectoryName: @"D:DestinationDirectory", overwriteFiles: false);

为缓存扩展 (caching extensions) 引入新指标

此版本为IMemoryCache添加了指标支持,主要的 API 包括:

  • MemoryCacheStatistics 用于记录命中/未命中/估算缓存大小的数据,以及针对IMemoryCache的计数
  • GetCurrentStatistics:返回MemoryCacheStatistics实例,TrackStatistics flag 未启用则返回 null。该库内置了可用于MemoryCache的实现

详情查看发布公告

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册