.Net MemoryCache AbsoluteExpiration 文档令人困惑

.Net MemoryCache AbsoluteExpiration documentation is confusing

添加缓存条目到System.Runtime.Caching.MemoryCache时,您可以指定 CacheItemPolicy 和 AbsoluteExpiration。根据文档 (https://msdn.microsoft.com/en-us/library/Dd780607(v=VS.110,d=hv.2).aspx),AbsoluteExpiration 是 "The period of time that must pass before a cache entry is evicted".

是的,这就是我想要的 - 指定 "the period of time" 之后我的缓存条目将过期。但是 AbsoluteExpiration 的类型是 DateTimeOffset 而不是 TimeSpan,所以它是 "point in time" 而不是 "period of time"。那我应该怎么设置呢?例如。如果我希望条目在 60 秒后过期,我应该将 AbsoluteExpiration 设置为 DateTimeOffset.UtcNow.AddSeconds(60) 吗?如果我将它设置为 DateTimeOffset.Now.AddSeconds(60),我会得到相同的结果吗?有理由使用其中之一吗?

是的,文档中的短语 "after a specified duration" 有点令人困惑,但 DateTimeOffset 类型和 AbsoluteExpiration 属性 名称毫无疑问。

关于如何构造a实例的方式DateTimeOffset:实际上在这种情况下没有任何区别。 DateTimeOffset.UtcNow.AddSeconds(60)DateTimeOffset.Now.AddSeconds(60) 将指向相同的绝对时间。这些日期时间会因时区而异,但缓存条目到期的时刻在两种情况下都是相同的。所以没有任何理由偏爱其中之一。