dotnet / dotnet/dotnet-api-docs

Document IDisposable implementation of ICacheEntry

Open
#7,702 1 comment 1 reaction 0 assignees View on GitHub
area-Extensions-Caching Pri3
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

**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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.