title: Func for async goes in deadlock?
body: <p><strong>Objective:</strong></p>
  
  <p>I am using redis for cache and trying to get a cache value if not available get from repo and set the cache value.</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>client side js keeps waiting forever and it seems to be in some type of deadlock</p>
  
  <p><strong>Code causing issue</strong></p>
  
  <pre><code>   return await _cacheStore.GetAsync("CacheKey", new TimeSpan(24, 0, 0),
                   async () =&gt;
                    await _repo.GetAllAsync()
                    );
  </code></pre>
  
  <p><strong>Code that works, but kinda redundant as i keep using this pattern a lot of places.</strong></p>
  
  <pre><code>    var data = await _cacheStore.GetAsync&lt;List&lt;objectType&gt;&gt;("cacheKey");
      if (data == null)
      {
          data = await _repo.GetAllAsync();
          _cacheStore.SetAsync&lt;List&lt;objectType&gt;&gt;("cacheKey", data, new TimeSpan(24, 0, 0));
      }
      return data;
  </code></pre>
  
  <p>//Possible Problem function below passing async method as Func?????
  <strong>Functions called by above code</strong></p>
  
  <pre><code>public static async Task &lt; T &gt; GetAsync &lt; T &gt; (this IRedisCacheStore source, string key, TimeSpan time, Func &lt; Task &lt; T &gt;&gt; fetch) where T: class {
   if (source.Exists(key)) {
    return await source.GetAsync &lt; T &gt; (key);
   } else {
    var result = fetch();
  
    if (result != null) {
     source.Set(key, result, time);
    }
  
    return await result;
   }
  }
  
  public async Task &lt; List &lt; ObjectType &gt;&gt; GetAllAsync() {
   var result = await _procExecutor.ExecuteProcAsync &lt; ObjectType &gt; ("Sproc", null);
  
   return (result ? ? new List &lt; ObjectType &gt; ()).ToList();
  }
  
  public async Task &lt; IEnumerable &lt; TResult &gt;&gt; ExecuteProcAsync &lt; TResult &gt; (string sproc, object param) {
    using(var conn = _connection.GetConnection()) {
     return await conn.QueryAsync &lt; TResult &gt; (sproc, param, commandType: CommandType.StoredProcedure);
    }
  </code></pre>
  
  <p>Here is my redis cacheStore</p>
  
  <pre><code>public interface IRedisCacheStore
  {
      bool Exists(string key);
      T Get&lt;T&gt;(string key);
      void Set&lt;T&gt;(string key, T value, TimeSpan expiredIn);
      void Remove(string key);
  
      Task&lt;bool&gt; ExistsAsync(string key);
      Task&lt;T&gt; GetAsync&lt;T&gt;(string key);
      Task SetAsync&lt;T&gt;(string key, T value, TimeSpan expiredIn);
      Task RemoveAsync(string key);
  }
  </code></pre>