-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Labels
Milestone
Description
IDisposable recommends a using
pattern as follows, where Dispose commits the entry to the cache:
using (var entry = MemoryCache.CreateEntry(cacheKey))
{
// The result is processed inside an entry
// such that the tokens are inherited.
entry.Value = CreateValue(params);
entry.SetOptions(options);
}
However, if CreateValue throws then the entry is still committed to the cache as null. Thus the using
pattern should not be used with ICacheEntry, and we should remove IDisposable to prevent it. Replace it with a Commit method.