Skip to content

Fix GetOrAddMany incorrect key-value mapping.#24734

Merged
hikalkan merged 1 commit intorel-10.0from
DistributedCache_Order_Problem-
Jan 24, 2026
Merged

Fix GetOrAddMany incorrect key-value mapping.#24734
hikalkan merged 1 commit intorel-10.0from
DistributedCache_Order_Problem-

Conversation

@maliming
Copy link
Member

@maliming maliming commented Jan 24, 2026

Refactored GetOrAddMany and GetOrAddManyAsync in DistributedCache to ensure returned key-value pairs are correctly mapped by key, regardless of order from the factory. Added unit tests to verify correct mapping and concurrency behavior.

Refactored GetOrAddMany and GetOrAddManyAsync in DistributedCache to ensure returned key-value pairs are correctly mapped by key, regardless of order from the factory. Added unit tests to verify correct mapping and concurrency behavior.
Copilot AI review requested due to automatic review settings January 24, 2026 07:03
@maliming maliming added this to the 10.0-patch-final milestone Jan 24, 2026
@maliming maliming changed the title Fix key-value mapping in GetOrAddMany and add tests Fix GetOrAddMany incorrect key-value mapping. Jan 24, 2026
Copy link
Contributor

Copilot AI left a comment

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 fixes a bug in the GetOrAddMany and GetOrAddManyAsync methods where returned key-value pairs were not correctly mapped by key when the factory returned values in a different order than expected. The fix refactors both methods to use a dictionary-based approach that ensures the returned array maintains the original input key order while correctly mapping each key to its value regardless of the order returned by the factory or retrieved from cache.

Changes:

  • Refactored GetOrAddMany and GetOrAddManyAsync to build a dictionary of cached results and map missing keys correctly
  • Added test GetOrAddManyAsync_Should_Return_Values_By_Key_With_Uow to verify correct mapping when using Unit of Work
  • Added test GetOrAddManyAsync_Should_Map_By_Key_Under_Concurrency to verify correct mapping under concurrent access when factory returns values in reversed order

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs Refactored GetOrAddMany and GetOrAddManyAsync to use dictionary-based mapping ensuring results are returned in the same order as input keys; removed trailing whitespace on line 22
framework/test/Volo.Abp.Caching.Tests/Volo/Abp/Caching/DistributedCache_Tests.cs Added two new tests to verify correct key-value mapping behavior with UoW and under concurrency; added System.Threading import

@maliming maliming requested a review from hikalkan January 24, 2026 07:32
@codecov
Copy link

codecov bot commented Jan 24, 2026

Codecov Report

❌ Patch coverage is 34.61538% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.01%. Comparing base (db98067) to head (7f43471).
⚠️ Report is 116 commits behind head on rel-10.0.

Files with missing lines Patch % Lines
...o.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs 34.61% 16 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           rel-10.0   #24734      +/-   ##
============================================
- Coverage     51.02%   51.01%   -0.02%     
============================================
  Files          3294     3299       +5     
  Lines        107441   107713     +272     
  Branches       8255     8266      +11     
============================================
+ Hits          54823    54950     +127     
- Misses        50923    51058     +135     
- Partials       1695     1705      +10     

☔ 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 hikalkan merged commit 76acd46 into rel-10.0 Jan 24, 2026
9 of 11 checks passed
@hikalkan hikalkan deleted the DistributedCache_Order_Problem- branch January 24, 2026 08:43
@hikalkan hikalkan added the bug label Jan 24, 2026
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