小编jxm*_*ler的帖子

How can I make this Concurrent Dictionary expire with a timer?

This code seems to do a good job of caching async method results. I would like to add some sort of expiration to it. I have tried Tuple but I was not successful in getting it to fully work / compile.

private static readonly ConcurrentDictionary<object, SemaphoreSlim> _keyLocks = new ConcurrentDictionary<object, SemaphoreSlim>();
    private static readonly ConcurrentDictionary<object, Tuple<List<UnitDTO>, DateTime>> _cache = new ConcurrentDictionary<object, Tuple<List<UnitDTO>, DateTime>>();

public async Task<string> GetSomethingAsync(string key)
{   
    string value;
    // get the semaphore specific to this key
    var …
Run Code Online (Sandbox Code Playgroud)

c# caching concurrentdictionary

6
推荐指数
1
解决办法
4483
查看次数

标签 统计

c# ×1

caching ×1

concurrentdictionary ×1