Skip to content

Add FindManyAsDictionaryAsync/GetManyAsDictionaryAsync to IEntityCache and add notnull constraint to TKey#25090

Merged
hikalkan merged 2 commits into
devfrom
feature/entity-cache-dictionary-methods
Mar 19, 2026
Merged

Add FindManyAsDictionaryAsync/GetManyAsDictionaryAsync to IEntityCache and add notnull constraint to TKey#25090
hikalkan merged 2 commits into
devfrom
feature/entity-cache-dictionary-methods

Conversation

@maliming

@maliming maliming commented Mar 16, 2026

Copy link
Copy Markdown
Member

Follows up on #25088 (comment)

  • Added FindManyAsDictionaryAsync and GetManyAsDictionaryAsync to IEntityCache, returning Dictionary<TKey, TEntityCacheItem?> and Dictionary<TKey, TEntityCacheItem> respectively.
  • Extracted a shared GetCacheItemDictionaryAsync helper in EntityCacheBase so all four batch methods reuse the same logic, removing all #pragma warning disable CS8714 suppressions.
  • Added where TKey : notnull constraint across the entire cache class hierarchy — required by Dictionary<TKey, TValue> and not a breaking change in practice.
  • Removed the in (contravariant) modifier from IEntityCache<TEntityCacheItem, TKey> as it is incompatible with dictionary return types.
  • Updated entity-cache.md and added tests for the new methods.

Copilot AI review requested due to automatic review settings March 16, 2026 01:12
@maliming maliming added this to the 10.3-preview milestone Mar 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / GetManyAsDictionaryAsync to IEntityCache and implemented them in EntityCacheBase.
  • Refactored EntityCacheBase batch logic into a shared helper to remove CS8714 suppressions.
  • 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.

Comment thread docs/en/framework/infrastructure/entity-cache.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / GetManyAsDictionaryAsync to IEntityCache.
  • Refactored EntityCacheBase batch logic to reuse a shared GetCacheItemDictionaryAsync helper and removed nullable-key warning suppressions.
  • Added where TKey : notnull across 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.

@maliming maliming requested review from EngincanV and hikalkan and removed request for EngincanV March 16, 2026 02:22
@hikalkan hikalkan merged commit c7ef58a into dev Mar 19, 2026
7 of 8 checks passed
@hikalkan hikalkan deleted the feature/entity-cache-dictionary-methods branch March 19, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants