dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
704 stars 1.55k forks source link

Document IDisposable implementation of ICacheEntry #7702

Open MaxKot opened 2 years ago

MaxKot commented 2 years ago

Help us make content visible

I was looking for details on how to use IMemoryCache and looked specifically into reference documentation entries:

Describe the new article

ICacheEntry implements IDisposable interface but its usage seems different from the other implementations of IDisposable. As can be seen in a comment here, Dispose method appears to be committing the new value to the cache and should not be called if the value to cache can not be created.

The documentation states that ICacheEntry implements IDisposable, but it does not provide any details as to how Dispose method should be implemented and what it should do. The only section showing CreateEntry usage in the tutorial on in-memory caching seems to be not following the guidance in the comment in MemoryCacheExtensions. Discussion here indicates that the IDisposable interface on the ICacheEntry is confusing.

I believe the expected behavior of ICacheEntry implementations should be documented in the Remarks section of ICacheEntry implementation and the right way to use the returned object should be documented in the Remarks section of IMemoryCache.CreateEntry documentation.

ghost commented 2 years ago

Tagging subscribers to this area: @dotnet/area-extensions-caching See info in area-owners.md if you want to be subscribed.

Issue Details
**Help us make content visible** I was looking for details on how to use IMemoryCache and looked specifically into reference documentation entries: * [ICacheEntry interface](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.memory.icacheentry?view=dotnet-plat-ext-6.0) * [IMemoryCache.CreateEntry(Object) Method](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.memory.imemorycache.createentry?view=dotnet-plat-ext-6.0) **Describe the new article** ICacheEntry implements IDisposable interface but its usage seems different from the other implementations of IDisposable. As can be seen in [a comment here](https://github.com/aspnet/Caching/blob/2.1.2/src/Microsoft.Extensions.Caching.Abstractions/MemoryCacheExtensions.cs#L97), Dispose method appears to be committing the new value to the cache and should not be called if the value to cache can not be created. The documentation states that ICacheEntry implements IDisposable, but it does not provide any details as to how Dispose method should be implemented and what it should do. The only [section showing CreateEntry usage](https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-6.0#cache-dependencies) in the tutorial on in-memory caching seems to be not following the guidance in the comment in MemoryCacheExtensions. [Discussion here](/dotnet/runtime/issues/36392) indicates that the IDisposable interface on the ICacheEntry is confusing. I believe the expected behavior of ICacheEntry implementations should be documented in the Remarks section of ICacheEntry implementation and the right way to use the returned object should be documented in the Remarks section of IMemoryCache.CreateEntry documentation.
Author: MaxKot
Assignees: -
Labels: `area-Extensions-Caching`
Milestone: -