Hi @AndRus ,
CS0149: Method name expected
To solve this issue, you can try to change the parameter type from Task<Func<T>>
to Func<Task<T>>
.
After modified, the result as below:
public sealed class CacheManager
{
private readonly IMemoryCache memoryCache;
public CacheManager(IMemoryCache memoryCache)
{
this.memoryCache = memoryCache;
}
public async Task<T> GetAsync<T>(string key, Func<Task<T>> generatorasync)
{
var cacheEntry = await
memoryCache.GetOrCreateAsync<T>(key, async entry =>
{
entry.SlidingExpiration = TimeSpan.FromSeconds(15 * 60);
return await generatorasync();
});
return cacheEntry;
}
}
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion