Skip to content

Remove IDisposable from ICacheEntry #36392

@Tratcher

Description

@Tratcher

https://github.com/aspnet/Caching/blob/65228be1d9aba6f2c360553868010f18706ee302/src/Microsoft.Extensions.Caching.Abstractions/ICacheEntry.cs#L13

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.

aspnet/Mvc#6522

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions