title: ASP.NET Core clear cache from IMemoryCache (set by Set method of CacheExtensions class)
body: <p><em>On first look this looks duplicate of <a href="https://stackoverflow.com/questions/48658912/clear-asp-net-core-2-0-imemorycache">this question</a>, but I am not asking how to clear cache for EF.</em></p>
  
  <p>How can I clear entire cache set by <code>IMemoryCache</code> interface?</p>
  
  <pre><code>    public CacheService(IMemoryCache memoryCache) 
      {
          this._memoryCache = memoryCache;
      }
  
      public async Task&lt;List&lt;string&gt;&gt; GetCacheItem()
      {
          if (!this._memoryCache.TryGetValue("Something", out List&lt;string&gt; list))
          {
              list= await this ...
  
              this._memoryCache.Set("Something", list, new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.NeverRemove));
          }
  
          return list;
      }
  </code></pre>
  
  <p>This is just an example. I have many classes/methods that are storing values to cache. Now I need to remove them all.</p>
  
  <p>My keys are, in some cases, created dynamically, so I don't know which keys I need to remove. Clear would be perfect.</p>
  
  <p>I could write my own interface and class which would internally use <code>IMemoryCache</code>, but this seems overkill. Is there any easier options?</p>