Base solution for your next web application
Open Closed

Calling anonymous async function while getting cache #10807


User avatar
0
[email protected] 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)
  • User Avatar
    0
    musa.demir created

    Hi @[email protected] 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();
        }
    );