c# .net core memory cache code example
Example 1: c# .net core memory cache
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddMemoryCache();
}
Example 2: c# .net core memory cache
[HttpGet]
public string Get()
{
cache.Set(“MyKey”, DateTime.Now.ToString());
return “This is a test method...”;
}
Example 3: c# .net core memory cache
private IMemoryCache cache;
public MyCacheController(IMemoryCache cache)
{
this.cache = cache;
}