Open Closed

Calling anonymous async function while getting cache #10807


0
anatrop@mkenga.com created

I want to use chache for custom login data

this is my cache call

var myCache = await _cacheManager.GetCache("MyCache") .GetAsync(AbpSession.UserId.ToString(), async () => await GetCacheFromSomewhere(AbpSession.UserId)) as NdCacheRecord;
private async Task<NdCacheRecord> GetCacheFromSomewhere(long? userId) { return new NdCacheRecord() } async () => await GetCacheFromSomewhere(AbpSession.UserId)

gives syntax error: Delegate Func<string, Task<object>> does not take 0 arguments

What should this look like?


1 Answer(s)
  • 0
    musa.demir created
    Support Team

    Hi @anatrop@mkenga.com You can use it like:

    NdCacheRecord cachedItem = await _cache.GetAsync("[CACHEKEY]",
        async () => // your task which returns the same type of your obj
        {
            return new NdCacheRecord();
        }
    );