Exactly how to utilize LazyCache in ASP.NET Core MVC 5

pixabay
pixabay
PM> Install-Package LazyCache
PM> Install-Package LazyCache.AspNetCore

Listed here is actually a checklist of the advantages of LazyCache at an easy glance:

public void ConfigureServices(IServiceCollection services)
{
services.AddLazyCache();
services.AddControllersWithViews();
}
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IAppCache _lazyCache = new CachingService();
public HomeController(ILogger<HomeController> logger, IAppCache cache)
{
_logger = logger;
_lazyCache = cache;
}
}
private async Task<List<string>> GetData()
{
return new List<string>()
{
"Joydip Kanjilal",
"Steve Smith",
"Rick Smith"
};
}
var data = await _lazyCache.GetOrAddAsync("Authors", GetData, DateTimeOffset.Now.AddMinutes(30));

Why am I here: Because I believe that we create ourselves, who we are. Subscribe https://tinyurl.com/9pxd4dbh

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store