Skip to content

Add FindManyAsync/GetManyAsync to IEntityCache and extract MapToValue virtual method#25088

Merged
maliming merged 5 commits into
devfrom
copilot/add-example-for-entity-cache
Mar 14, 2026
Merged

Add FindManyAsync/GetManyAsync to IEntityCache and extract MapToValue virtual method#25088
maliming merged 5 commits into
devfrom
copilot/add-example-for-entity-cache

Conversation

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #25087

Add batch retrieval methods to IEntityCache and improve extensibility of EntityCacheWithObjectMapper.

Batch retrieval (FindManyAsync / GetManyAsync)

  • Added FindManyAsync(IEnumerable<TKey> ids) and GetManyAsync(IEnumerable<TKey> ids) to IEntityCache<TEntityCacheItem, TKey>, mirroring the existing FindAsync/GetAsync semantics.
  • Internally uses IDistributedCache.GetOrAddManyAsync so only cache-missed IDs hit the database.
  • Duplicate IDs are de-duplicated before querying the cache/database, then the result list preserves the original order (including duplicates).
  • Passes includeDetails: true to Repository.GetListAsync to keep behavior consistent with the single-entity methods.

Custom object mapping (MapToValue)

  • Extracted entity-to-cache-item mapping from EntityCacheWithObjectMapper.MapToCacheItem into a new protected virtual MapToValue(TEntity entity) method, allowing derived classes to override just the mapping logic without reimplementing the full MapToCacheItem.

ReplaceEntityCache extension method

  • Added ReplaceEntityCache<TEntityCache, TEntity, TEntityCacheItem, TKey> to allow replacing the default entity cache implementation with a custom one.
  • Conditionally configures AbpSystemTextJsonSerializerModifiersOptions when TEntity == TEntityCacheItem to ensure correct deserialization of the Entity<TKey>.Id property.

Docs

  • Added documentation sections for batch retrieval usage and custom mapping via MapToValue override.
  • Fixed float to decimal for Price property in all doc examples.

… virtual method

Co-authored-by: hikalkan <1210527+hikalkan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add example for IEntityCache.GetManyAsync method Add GetManyAsync/FindManyAsync to IEntityCache and extract MapToValue virtual method Mar 13, 2026
Copilot AI requested a review from hikalkan March 13, 2026 19:10
@maliming maliming marked this pull request as ready for review March 14, 2026 02:34
Copilot AI review requested due to automatic review settings March 14, 2026 02:34

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

Adds batch retrieval APIs to ABP’s entity cache abstraction and improves extensibility of cache-item mapping for object-mapper-based caches.

Changes:

  • Introduces FindManyAsync / GetManyAsync on IEntityCache<,> for order-preserving batch retrieval.
  • Implements batch retrieval in EntityCacheBase via IDistributedCache.GetOrAddManyAsync, extracting a virtual GetOrAddManyCacheItemsAsync helper.
  • Extracts MapToValue as a protected virtual method in EntityCacheWithObjectMapper and documents batch usage + custom mapping (plus adds/updates related tests and DI extension).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityCache_Tests.cs Adds test coverage for batch retrieval and custom mapping override behavior.
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs Registers/uses ReplaceEntityCache for test scenarios.
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/IEntityCache.cs Adds the new batch API surface to the entity cache contract.
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheWithObjectMapper.cs Extracts entity→cache-item mapping into overridable MapToValue.
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheServiceCollectionExtensions.cs Adds ReplaceEntityCache DI helper for swapping implementations.
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs Implements FindManyAsync / GetManyAsync using distributed cache bulk APIs.
docs/en/framework/infrastructure/entity-cache.md Documents batch retrieval and custom mapping override via MapToValue.

Comment thread docs/en/framework/infrastructure/entity-cache.md
@maliming maliming changed the title Add GetManyAsync/FindManyAsync to IEntityCache and extract MapToValue virtual method Add FindManyAsync/GetManyAsync to IEntityCache and extract MapToValue virtual method Mar 14, 2026
@maliming maliming requested a review from Copilot March 14, 2026 02:57

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

Adds batch retrieval APIs to ABP’s entity cache abstraction and improves extensibility for cache item mapping, plus supporting tests, DI extension, and docs.

Changes:

  • Added FindManyAsync / GetManyAsync to IEntityCache and implemented them in EntityCacheBase using IDistributedCache.GetOrAddManyAsync.
  • Extracted MapToValue as a protected virtual method in EntityCacheWithObjectMapper to allow overriding mapping without reimplementing wrapper creation.
  • Introduced ReplaceEntityCache DI extension + test coverage and updated docs (including Price examples from float to decimal).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityCache_Tests.cs Adds tests for batch cache APIs, duplicate-id behavior, and custom mapping via ReplaceEntityCache.
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs Registers/replaces entity caches to validate ReplaceEntityCache scenarios in tests.
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/IEntityCache.cs Extends the public cache interface with batch retrieval methods.
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheWithObjectMapper.cs Extracts mapping into overridable MapToValue for extensibility.
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheServiceCollectionExtensions.cs Adds ReplaceEntityCache registration helper and conditional JSON modifier configuration.
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs Implements batch retrieval and shared GetOrAddManyCacheItemsAsync logic.
docs/en/framework/infrastructure/entity-cache.md Documents batch APIs and MapToValue customization; updates Price type examples.

@maliming maliming merged commit fdcd6fe into dev Mar 14, 2026
3 checks passed
@maliming maliming deleted the copilot/add-example-for-entity-cache branch March 14, 2026 03:54
@codecov

codecov Bot commented Mar 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.59259% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.64%. Comparing base (3786ddf) to head (08c6521).
⚠️ Report is 39 commits behind head on dev.

Files with missing lines Patch % Lines
.../Caching/EntityCacheServiceCollectionExtensions.cs 56.25% 6 Missing and 1 partial ⚠️
...olo/Abp/Domain/Entities/Caching/EntityCacheBase.cs 89.65% 3 Missing and 3 partials ⚠️
...in/Entities/Caching/EntityCacheWithObjectMapper.cs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #25088      +/-   ##
==========================================
+ Coverage   50.52%   50.64%   +0.12%     
==========================================
  Files        3464     3465       +1     
  Lines      116360   116732     +372     
  Branches     8810     8819       +9     
==========================================
+ Hits        58787    59116     +329     
- Misses      55789    55817      +28     
- Partials     1784     1799      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hikalkan

Copy link
Copy Markdown
Member

@copilot can you add a new methods: GetManyAsDictionaryAsync and GetManyAsDictionaryAsync, similar to FindManyAsync / GetManyAsync but returns dictionary of entities instead of a list. (don't make unnecessary duplication in the internal logic, instead try to use a common login inside the class). Also, update the documentation.
Create a separate PR please.

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.

IEntityCache.GetManyAsync method

4 participants