温馨提示:本文翻译自stackoverflow.com,查看原文请点击:c# - How can I update the transactions status when cache expire?
.net asp.net-core asp.net-mvc c# asp.net-core-3.0

c# - 缓存过期后如何更新交易状态?

发布于 2020-04-04 00:00:15
var cacheExpirationOptions = new MemoryCacheEntryOptions 
{
    AbsoluteExpiration = DateTime.Now.AddMinutes(5),
    Priority = CacheItemPriority.Normal,
};
_memoryCache.Set(fakeTransactionId, transaction.Id,
    cacheExpirationOptions.RegisterPostEvictionCallback((key, value, reason, state) = > {
        TransactionStatusUpdate(transaction.Id, TransactionStatusType.UrlExpired);
    }));

我想在默认进程过期时更新该进程,该怎么办?

查看更多

提问者
venogn
被浏览
100
venogn 2020-02-07 18:09
        var expirationTime = DateTime.Now.AddMinutes(30);
        var expirationToken = new CancellationChangeToken(
            new CancellationTokenSource(TimeSpan.FromMinutes(31)).Token);

        var cacheEntryOptions = new MemoryCacheEntryOptions()
         .SetPriority(CacheItemPriority.NeverRemove)
         .SetAbsoluteExpiration(expirationTime)
         .AddExpirationToken(expirationToken)
         .RegisterPostEvictionCallback(callback: EvictionCallback, state: this);
        _memoryCache.Set(fakeTransactionId, transaction.Id, cacheEntryOptions);

我发现,当expirationTime完成EvictionCallback触发时。

最新帖子

最新文章