title: How can I make this Concurrent Dictionary expire with a timer?
body: <p>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.</p>
  
  <pre><code>private static readonly ConcurrentDictionary&lt;object, SemaphoreSlim&gt; _keyLocks = new ConcurrentDictionary&lt;object, SemaphoreSlim&gt;();
      private static readonly ConcurrentDictionary&lt;object, Tuple&lt;List&lt;UnitDTO&gt;, DateTime&gt;&gt; _cache = new ConcurrentDictionary&lt;object, Tuple&lt;List&lt;UnitDTO&gt;, DateTime&gt;&gt;();
  
  public async Task&lt;string&gt; GetSomethingAsync(string key)
  {   
      string value;
      // get the semaphore specific to this key
      var keyLock = _keyLocks.GetOrAdd(key, x =&gt; new SemaphoreSlim(1));
      await keyLock.WaitAsync();
      try
      {
          // try to get value from cache
          if (!_cache.TryGetValue(key, out value))
          {
              // if value isn't cached, get it the long way asynchronously
              value = await GetSomethingTheLongWayAsync();
  
              // cache value
              _cache.TryAdd(key, value);
          }
      }
      finally
      {
          keyLock.Release();
      }
      return value;
  }
  </code></pre>