madskristensen / WebEssentials.AspNetCore.OutputCaching

Other
52 stars 17 forks source link

Better Clear() impl for concurrent access #22

Closed jodydonetti closed 3 years ago

jodydonetti commented 3 years ago

Just a small change to better handle concurrent usage of Clear(), because with the old code this may happen:

public void Clear()
{
  if (_cache != null)
  {
    _cache.Dispose();
    // AFTER THIS LINE ACCESS TO _cache WOULD THROW AN ObjectDisposedException
  }

  _cache = new MemoryCache(new MemoryCacheOptions());
}
madskristensen commented 3 years ago

Thanks