Skip to content

Avoid adding values to cache if the current value is the same as adding value #6673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

RushanNanayakkara
Copy link
Contributor

@RushanNanayakkara RushanNanayakkara commented Apr 9, 2025

Purpose

When there is a cache miss the value is added to the cache. But in a clustered environment many nodes may simultaneously read the initial value as null and then try to add the value. But at the time of adding the value, the first one to complete adding the value succeeds but other processes proceed to update the value instead of adding the value.

However while adding doesn't invalidate cache, updating does. But since if the new value is the same as the existing one, there's no need to update the value and then invalidate the cache. This behaviour causes unnecessary cache invalidations in clustered environments. This then leads to unnecessary db reads to retrieve the same value again and again.

Changes of this PR performs an equality check between the new value and the value in the cache and skips updating if the values are the same. This avoids unnecessary cache invalidations.

Related Issue/s

Dependent on

@RushanNanayakkara RushanNanayakkara changed the title Avoid adding values to cache if the current value is the same as addi… Avoid adding values to cache if the current value is the same as adding value Apr 9, 2025
@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/14357216988

Copy link

codecov bot commented Apr 9, 2025

Codecov Report

Attention: Patch coverage is 0% with 29 lines in your changes missing coverage. Please review.

Project coverage is 48.11%. Comparing base (5ec9fbf) to head (5ec17d7).
Report is 17 commits behind head on master.

Files with missing lines Patch % Lines
...tity/claim/metadata/mgt/cache/LocalClaimCache.java 0.00% 14 Missing ⚠️
...arbon/identity/claim/metadata/mgt/model/Claim.java 0.00% 6 Missing ⚠️
...ity/claim/metadata/mgt/model/AttributeMapping.java 0.00% 5 Missing ⚠️
.../identity/claim/metadata/mgt/model/LocalClaim.java 0.00% 4 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6673      +/-   ##
============================================
- Coverage     48.41%   48.11%   -0.30%     
+ Complexity    16512    16177     -335     
============================================
  Files          1833     1833              
  Lines        110201   108772    -1429     
  Branches      20972    20514     -458     
============================================
- Hits          53355    52338    -1017     
+ Misses        49633    49252     -381     
+ Partials       7213     7182      -31     
Flag Coverage Δ
unit 32.01% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/14357216988
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

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

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/14357216988

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants