dotnet / dotnet/dotnet-api-docs
Document IDisposable implementation of ICacheEntry
- Lingua principale
- C#
- Stelle
- 949
- Fork
- 1.7k
- Merge medio
- 2g 19h
- PR unite (30g)
- 52
Descrizione
**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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con le pagine di riferimento di ICacheEntry e IMemoryCache.CreateEntry, quindi leggi il commento collegato in MemoryCacheExtensions.cs e la discussione correlata in dotnet/runtime/issues/36392. Aggiorna le sezioni Remarks per spiegare il comportamento di IDisposable e l'uso corretto della voce restituita, incluso ciò che fa Dispose e quando non deve essere chiamato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 2/5
- Tempo stimato
- Mezza giornata
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100