private IMemoryCache cache; public MyCacheController(IMemoryCache cache) { this.cache = cache; }
[HttpGet] public string Get() { cache.Set(“MyKey”, DateTime.Now.ToString()); return “This is a test method...”; }
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddMemoryCache(); }