Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

ASP.NET Core set update clear cache from IMemoryCache (set by Set method of CacheExtensions class)

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);
}

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Core #set #update #clear #cache #IMemoryCache #Set #method #CacheExtensions
ADD COMMENT
Topic
Name
6+4 =