Internally it uses IMemoryCache.
Use case is exactly the same with 2 additional features:
Clear all items from memory cache
Iterate through all key/value pairs
You have to register singleton:
serviceCollection.AddSingleton<IMyCache, MyMemoryCache>();
Use case:
public MyController(IMyCache cache)
{
this._cache = cache;
}
[HttpPut]
public IActionResult ClearCache()
{
this._cache.Clear();
return new JsonResult(true);
}
[HttpGet]
public IActionResult ListCache()
{
var result = this._cache.Select(t => new
{
Key = t.Key,
Value = t.Value
}).ToArray();
return new JsonResult(result);
}