Add FindManyAsync/GetManyAsync to IEntityCache and extract MapToValue virtual method#25088
Conversation
… virtual method Co-authored-by: hikalkan <1210527+hikalkan@users.noreply.github.com>
There was a problem hiding this comment.
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/GetManyAsynconIEntityCache<,>for order-preserving batch retrieval. - Implements batch retrieval in
EntityCacheBaseviaIDistributedCache.GetOrAddManyAsync, extracting a virtualGetOrAddManyCacheItemsAsynchelper. - Extracts
MapToValueas aprotected virtualmethod inEntityCacheWithObjectMapperand 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. |
…ync/GetManyAsync to handle duplicate IDs
FindManyAsync/GetManyAsync to IEntityCache and extract MapToValue virtual method
There was a problem hiding this comment.
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/GetManyAsynctoIEntityCacheand implemented them inEntityCacheBaseusingIDistributedCache.GetOrAddManyAsync. - Extracted
MapToValueas aprotected virtualmethod inEntityCacheWithObjectMapperto allow overriding mapping without reimplementing wrapper creation. - Introduced
ReplaceEntityCacheDI extension + test coverage and updated docs (includingPriceexamples fromfloattodecimal).
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. |
…istency with GetAsync
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
|
@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. |
Fixes #25087
Add batch retrieval methods to
IEntityCacheand improve extensibility ofEntityCacheWithObjectMapper.Batch retrieval (
FindManyAsync/GetManyAsync)FindManyAsync(IEnumerable<TKey> ids)andGetManyAsync(IEnumerable<TKey> ids)toIEntityCache<TEntityCacheItem, TKey>, mirroring the existingFindAsync/GetAsyncsemantics.IDistributedCache.GetOrAddManyAsyncso only cache-missed IDs hit the database.includeDetails: truetoRepository.GetListAsyncto keep behavior consistent with the single-entity methods.Custom object mapping (
MapToValue)EntityCacheWithObjectMapper.MapToCacheIteminto a newprotected virtual MapToValue(TEntity entity)method, allowing derived classes to override just the mapping logic without reimplementing the fullMapToCacheItem.ReplaceEntityCacheextension methodReplaceEntityCache<TEntityCache, TEntity, TEntityCacheItem, TKey>to allow replacing the default entity cache implementation with a custom one.AbpSystemTextJsonSerializerModifiersOptionswhenTEntity == TEntityCacheItemto ensure correct deserialization of theEntity<TKey>.Idproperty.Docs
MapToValueoverride.floattodecimalforPriceproperty in all doc examples.