关于 c#:MemoryCache AbsoluteExpiration | 珊瑚贝

MemoryCache AbsoluteExpiration


当使用 MemoryCache 时,可以设置

  • AbsoluteExpiration
  • AbsoluteExpirationRelativeToNow

示例:

1
2
3
4
5
6
    cache.GetOrCreate(“key”, f =>
    {
         f.AbsoluteExpiration = new DateTimeOffset(DateTime.Today.AddDays(1));
         f.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
        return“item”;
    });

这两个属性可以同时设置,先过期的那个会生效吗?
还是最后一个设置的属性是”主”?

  • 因为它们是属性。设置 AbsoluteExpirationRelativeToNow 后 AbsoluteExpiration 的值是否会改变?如果是这样,则只有一个潜在价值。


由于这些属性属于接口 (ICacheEntry) – 它们的行为方式取决于具体的实现。如果我们采用默认的 MemoryCache (和相应的 CacheEntry 实现) – 那么是的,它们都可以设置,并且因为它们都代表绝对过期,所以较早发生的将生效,而另一个将被忽略。


来源:https://www.codenong.com/49190235/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8724.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?