Warm tip: This article is reproduced from stackoverflow.com, please click
.net asp.net-core asp.net-mvc c# asp.net-core-3.0

How can I update the transactions status when cache expire?

发布于 2020-04-03 23:37:34
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);
    }));

I want to update the process when the default process expires, what should I do?

Questioner
venogn
Viewed
70
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);

I found, when expirationTime finish EvictionCallback triggering.