Add FindManyAsDictionaryAsync/GetManyAsDictionaryAsync to IEntityCache and add notnull constraint to TKey#25090
Merged
Merged
Conversation
…e and add notnull constraint to TKey
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends ABP’s entity caching abstraction with dictionary-based batch retrieval methods and updates the cache type hierarchy to support Dictionary<TKey, TValue> safely by constraining TKey to notnull.
Changes:
- Added
FindManyAsDictionaryAsync/GetManyAsDictionaryAsynctoIEntityCacheand implemented them inEntityCacheBase. - Refactored
EntityCacheBasebatch logic into a shared helper to removeCS8714suppressions. - Updated docs and added tests covering the new dictionary-based APIs.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityCache_Tests.cs | Adds test coverage for dictionary-based batch methods (null handling, exceptions, duplicates). |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/IEntityCache.cs | Extends the interface with dictionary-returning APIs; adds notnull constraint and removes in variance. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs | Implements new dictionary APIs and extracts shared dictionary-building helper. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheWithoutCacheItem.cs | Propagates where TKey : notnull constraint. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheWithObjectMapper.cs | Propagates where TKey : notnull constraint. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheWithObjectMapperContext.cs | Propagates where TKey : notnull constraint. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheServiceCollectionExtensions.cs | Propagates where TKey : notnull constraint to registration helpers. |
| docs/en/framework/infrastructure/entity-cache.md | Documents dictionary-based batch retrieval methods. |
…fix doc return type description
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends ABP’s IEntityCache batch APIs by adding dictionary-returning overloads and tightens generic key constraints to align with Dictionary<TKey, TValue> and DistributedCache<TCacheItem, TCacheKey> requirements.
Changes:
- Added
FindManyAsDictionaryAsync/GetManyAsDictionaryAsynctoIEntityCache. - Refactored
EntityCacheBasebatch logic to reuse a sharedGetCacheItemDictionaryAsynchelper and removed nullable-key warning suppressions. - Added
where TKey : notnullacross the entity cache type hierarchy and updated docs/tests accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityCache_Tests.cs | Adds test coverage for the new dictionary-based batch APIs and duplicate-id behavior. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/IEntityCache.cs | Introduces the new dictionary-returning methods; removes contravariance and adds notnull constraint on TKey. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs | Implements the new APIs and consolidates shared batch retrieval logic via a dictionary helper. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheWithoutCacheItem.cs | Propagates where TKey : notnull constraint. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheWithObjectMapper.cs | Propagates where TKey : notnull constraint. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheWithObjectMapperContext.cs | Propagates where TKey : notnull constraint. |
| framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheServiceCollectionExtensions.cs | Updates DI extension methods to require TKey : notnull. |
| docs/en/framework/infrastructure/entity-cache.md | Documents list-based vs dictionary-based batch retrieval APIs and their semantics. |
hikalkan
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows up on #25088 (comment)
FindManyAsDictionaryAsyncandGetManyAsDictionaryAsynctoIEntityCache, returningDictionary<TKey, TEntityCacheItem?>andDictionary<TKey, TEntityCacheItem>respectively.GetCacheItemDictionaryAsynchelper inEntityCacheBaseso all four batch methods reuse the same logic, removing all#pragma warning disable CS8714suppressions.where TKey : notnullconstraint across the entire cache class hierarchy — required byDictionary<TKey, TValue>and not a breaking change in practice.in(contravariant) modifier fromIEntityCache<TEntityCacheItem, TKey>as it is incompatible with dictionary return types.entity-cache.mdand added tests for the new methods.