Skip to content

[Sync][master -> next][#7871]: Refactor cache operations to use read-safe methods for concurrent environments#7913

Merged
ThaminduR merged 4 commits intonextfrom
sync-pr-7871-to-next
Mar 26, 2026
Merged

[Sync][master -> next][#7871]: Refactor cache operations to use read-safe methods for concurrent environments#7913
ThaminduR merged 4 commits intonextfrom
sync-pr-7871-to-next

Conversation

@github-actions
Copy link
Copy Markdown

🤖 Auto-sync from master

This PR automatically syncs the changes from #7871 to the next branch.

Original PR: #7871
Author: @Zeta201
Total commits: 4
Workflow run: https://github.com/wso2/carbon-identity-framework/actions/runs/23485460069

Commits:

fc20bcfe9eff Fix duplicated code
b31ca3189437 Fix log4j failure
ab04934cd9ae Add and update unit tests and TestNG configurations
c8c937f1ac66 Add and update unit tests for cache behavior and refactored components

Comment on lines 92 to +93
}
actionCacheByType.addToCache(cacheKey, new ActionCacheEntry(actions), tenantDomain);
actionCacheByType.addToCacheOnRead(cacheKey, new ActionCacheEntry(actions), tenantDomain);
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.

Log Improvement Suggestion No: 1

Suggested change
}
actionCacheByType.addToCache(cacheKey, new ActionCacheEntry(actions), tenantDomain);
actionCacheByType.addToCacheOnRead(cacheKey, new ActionCacheEntry(actions), tenantDomain);
}
LOG.info("Cache updated with actions for Action Type: " + actionType);
actionCacheByType.addToCacheOnRead(cacheKey, new ActionCacheEntry(actions), tenantDomain);

LOG.debug("Entry fetched from DB for API Resource " + apiId + ". Updating cache");
}
apiResourceCacheById.addToCache(cacheKey, new APIResourceCacheEntry(apiResource), tenantId);
apiResourceCacheById.addToCacheOnRead(cacheKey, new APIResourceCacheEntry(apiResource), tenantId);
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.

Log Improvement Suggestion No: 2

Suggested change
apiResourceCacheById.addToCacheOnRead(cacheKey, new APIResourceCacheEntry(apiResource), tenantId);
if (LOG.isDebugEnabled()) {
LOG.debug("Entry fetched from DB for API Resource " + apiId + ". Updating cache");
}
if (LOG.isDebugEnabled()) {
LOG.debug("Adding API Resource to cache with ID: " + apiId);
}

LOG.debug("Entry fetched from DB for API Resource " + identifier + ". Updating cache");
}
apiResourceCacheByIdentifier.addToCache(cacheKey, new APIResourceCacheEntry(apiResource), tenantId);
apiResourceCacheByIdentifier.addToCacheOnRead(cacheKey, new APIResourceCacheEntry(apiResource), tenantId);
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.

Log Improvement Suggestion No: 3

Suggested change
apiResourceCacheByIdentifier.addToCacheOnRead(cacheKey, new APIResourceCacheEntry(apiResource), tenantId);
if (LOG.isDebugEnabled()) {
LOG.debug("Entry fetched from DB for API Resource " + identifier + ". Updating cache");
}
if (LOG.isDebugEnabled()) {
LOG.debug("Adding API Resource to cache with identifier: " + identifier);
}

Comment on lines +170 to +174
public void addToCacheOnRead(K key, V entry) {

if (!isEnabled()) {
return;
}
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.

Log Improvement Suggestion No: 4

Suggested change
public void addToCacheOnRead(K key, V entry) {
if (!isEnabled()) {
return;
}
public void addToCacheOnRead(K key, V entry) {
if (!isEnabled()) {
if (log.isDebugEnabled()) {
log.debug("Cache is disabled. Skipping cache population for key.");
}
return;
}

Comment on lines +182 to +185
Cache<K, V> cache = getBaseCache();
if (cache != null) {
cache.putOnRead(key, entry);
}
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.

Log Improvement Suggestion No: 5

Suggested change
Cache<K, V> cache = getBaseCache();
if (cache != null) {
cache.putOnRead(key, entry);
}
Cache<K, V> cache = getBaseCache();
if (cache != null) {
cache.putOnRead(key, entry);
if (log.isDebugEnabled()) {
log.debug("Cache entry added during read operation.");
}
} else {
log.warn("Base cache is null. Unable to add cache entry during read operation.");
}

Comment on lines +56 to +58
public void addToCacheOnRead(RandomPasswordContainerCacheKey key, RandomPasswordContainerCacheEntry entry) {

super.addToCacheOnRead(key, entry, CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
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.

Log Improvement Suggestion No: 6

Suggested change
public void addToCacheOnRead(RandomPasswordContainerCacheKey key, RandomPasswordContainerCacheEntry entry) {
super.addToCacheOnRead(key, entry, CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
public void addToCacheOnRead(RandomPasswordContainerCacheKey key, RandomPasswordContainerCacheEntry entry) {
if (log.isDebugEnabled()) {
log.debug("Adding random password container to cache on read for key: " + key.getKey());
}
super.addToCacheOnRead(key, entry, CarbonContext.getThreadLocalCarbonContext().getTenantDomain());

Comment on lines +100 to 101
authenticatorCache.addToCacheOnRead(cacheKey, new AuthenticatorCacheEntry(authenticatorConfig), tenantId);
LOG.debug("Entry fetched from DB for authenticator " + authenticatorConfigName + ". Adding cache entry.");
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.

Log Improvement Suggestion No: 7

Suggested change
authenticatorCache.addToCacheOnRead(cacheKey, new AuthenticatorCacheEntry(authenticatorConfig), tenantId);
LOG.debug("Entry fetched from DB for authenticator " + authenticatorConfigName + ". Adding cache entry.");
authenticatorCache.addToCacheOnRead(cacheKey, new AuthenticatorCacheEntry(authenticatorConfig), tenantId);
if (LOG.isDebugEnabled()) {
LOG.debug("Entry fetched from DB for authenticator " + authenticatorConfigName + ". Adding cache entry.");
}

Comment on lines 2140 to +2141
}
ServiceProviderTemplateCache.getInstance().addToCache(templateCacheKey, spTemplate, tenantDomain);
ServiceProviderTemplateCache.getInstance().addToCacheOnRead(templateCacheKey, spTemplate, tenantDomain);
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.

Log Improvement Suggestion No: 8

Suggested change
}
ServiceProviderTemplateCache.getInstance().addToCache(templateCacheKey, spTemplate, tenantDomain);
ServiceProviderTemplateCache.getInstance().addToCacheOnRead(templateCacheKey, spTemplate, tenantDomain);
}
if (log.isDebugEnabled()) {
log.debug(String.format("Adding template with name: %s to cache for tenant: %s", templateName, tenantDomain));
}
ServiceProviderTemplateCache.getInstance().addToCacheOnRead(templateCacheKey, spTemplate, tenantDomain);

Comment on lines 167 to 171
ServiceProviderCacheInboundAuthKey clientKey = new ServiceProviderCacheInboundAuthKey(clientId, type);
ServiceProviderCacheInboundAuthEntry clientEntry = new ServiceProviderCacheInboundAuthEntry(appName,
tenantDomain);
appCacheByInboundAuth.addToCache(clientKey, clientEntry, tenantDomain);
appCacheByInboundAuth.addToCacheOnRead(clientKey, clientEntry, tenantDomain);
}
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.

Log Improvement Suggestion No: 9

Suggested change
ServiceProviderCacheInboundAuthKey clientKey = new ServiceProviderCacheInboundAuthKey(clientId, type);
ServiceProviderCacheInboundAuthEntry clientEntry = new ServiceProviderCacheInboundAuthEntry(appName,
tenantDomain);
appCacheByInboundAuth.addToCache(clientKey, clientEntry, tenantDomain);
appCacheByInboundAuth.addToCacheOnRead(clientKey, clientEntry, tenantDomain);
}
if (appName != null) {
ServiceProviderCacheInboundAuthKey clientKey = new ServiceProviderCacheInboundAuthKey(clientId, type);
ServiceProviderCacheInboundAuthEntry clientEntry = new ServiceProviderCacheInboundAuthEntry(appName,
tenantDomain);
if (log.isDebugEnabled()) {
log.debug("Adding service provider to cache for client: " + clientId + ", type: " + type);
}
appCacheByInboundAuth.addToCacheOnRead(clientKey, clientEntry, tenantDomain);
}

Comment on lines 140 to +141
AuthorizedAPICacheEntry cacheEntry = new AuthorizedAPICacheEntry(authorizedAPI);
authorizedAPICache.addToCache(cacheKey, cacheEntry, tenantId);
authorizedAPICache.addToCacheOnRead(cacheKey, cacheEntry, tenantId);
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.

Log Improvement Suggestion No: 11

Suggested change
AuthorizedAPICacheEntry cacheEntry = new AuthorizedAPICacheEntry(authorizedAPI);
authorizedAPICache.addToCache(cacheKey, cacheEntry, tenantId);
authorizedAPICache.addToCacheOnRead(cacheKey, cacheEntry, tenantId);
AuthorizedAPICacheEntry cacheEntry = new AuthorizedAPICacheEntry(authorizedAPI);
if (LOG.isDebugEnabled()) {
LOG.debug("Adding authorized API to cache for appId: " + appId + ", apiId: " + apiId);
}

Comment on lines +326 to +328
private void addDefaultAuthSeqToCacheOnRead(DefaultAuthenticationSequence sequence, String tenantDomain) {

if (DefaultAuthSeqMgtCache.getInstance().isEnabled()) {
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.

Log Improvement Suggestion No: 13

Suggested change
private void addDefaultAuthSeqToCacheOnRead(DefaultAuthenticationSequence sequence, String tenantDomain) {
if (DefaultAuthSeqMgtCache.getInstance().isEnabled()) {
private void addDefaultAuthSeqToCacheOnRead(DefaultAuthenticationSequence sequence, String tenantDomain) {
if (DefaultAuthSeqMgtCache.getInstance().isEnabled()) {
if (log.isDebugEnabled()) {
log.debug("Adding default authentication sequence: " + sequence.getName() +
" to cache on read for tenant: " + tenantDomain);
}

Comment on lines +83 to +86
public void addToCacheOnRead(K key, V entry) {

addToCacheOnRead(key, entry, getLoginTenantDomainFromContext());
}
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.

Log Improvement Suggestion No: 14

Suggested change
public void addToCacheOnRead(K key, V entry) {
addToCacheOnRead(key, entry, getLoginTenantDomainFromContext());
}
public void addToCacheOnRead(K key, V entry) {
if (log.isDebugEnabled()) {
log.debug("Adding cache entry on read for key: " + key);
}
addToCacheOnRead(key, entry, getLoginTenantDomainFromContext());

Comment on lines 89 to +91

if (entry.getContext() != null && entry.getContext().getProperties() != null) {
Iterator it = entry.getContext().getProperties().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> item = (Map.Entry<String, Object>) it.next();
if (!(item.getValue() instanceof Serializable)) {
it.remove();
}
}
if (log.isDebugEnabled()) {
String message = "[ Context Id : " + key.getContextId() +
", Cache type : " + AUTHENTICATION_CONTEXT_CACHE_NAME +
", Operation : STORE ]";
log.debug("Authentication context is stored with details " + message);
}
if (entry.getContext() != null) {
try {
AuthenticationContextLoader.getInstance().optimizeAuthenticationContext(entry.getContext());
} catch (SessionDataStorageOptimizationClientException e) {
if (log.isDebugEnabled()) {
log.debug("Client error occurred while optimizing the Authentication context with " +
"context id: " + entry.getContext().getContextIdentifier(), e);
}
return;
} catch (SessionDataStorageOptimizationServerException e) {
log.error("Server error occurred while optimizing the Authentication context with " +
"context id: " + entry.getContext().getContextIdentifier(), e);
return;
} catch (SessionDataStorageOptimizationException e) {
if (log.isDebugEnabled()) {
log.debug("Error occurred while optimizing the Authentication context with " +
"context id: " + entry.getContext().getContextIdentifier(), e);
}
return;
}
}
SessionDataStore.getInstance().storeSessionData(key.getContextId(), AUTHENTICATION_CONTEXT_CACHE_NAME,
entry, tenantId);
try {
AuthenticationContextLoader.getInstance().loadAuthenticationContext(entry.getContext());
} catch (SessionDataStorageOptimizationClientException e) {
if (log.isDebugEnabled()) {
log.debug("Client error occurred while loading optimized authentication context"
+ " with context id: " + entry.getContext().getContextIdentifier(), e);
}
} catch (SessionDataStorageOptimizationServerException e) {
log.error("Server error occurred while loading optimized authentication " +
"context with context id: " + entry.getContext().getContextIdentifier(), e);
} catch (SessionDataStorageOptimizationException e) {
if (log.isDebugEnabled()) {
log.debug("Error occurred while loading optimized authentication " +
"context with context id: " + entry.getContext().getContextIdentifier(), e);
}
}
}
public void addToCacheOnRead(AuthenticationContextCacheKey key, AuthenticationContextCacheEntry entry) {

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.

Log Improvement Suggestion No: 15

Suggested change
if (entry.getContext() != null && entry.getContext().getProperties() != null) {
Iterator it = entry.getContext().getProperties().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> item = (Map.Entry<String, Object>) it.next();
if (!(item.getValue() instanceof Serializable)) {
it.remove();
}
}
if (log.isDebugEnabled()) {
String message = "[ Context Id : " + key.getContextId() +
", Cache type : " + AUTHENTICATION_CONTEXT_CACHE_NAME +
", Operation : STORE ]";
log.debug("Authentication context is stored with details " + message);
}
if (entry.getContext() != null) {
try {
AuthenticationContextLoader.getInstance().optimizeAuthenticationContext(entry.getContext());
} catch (SessionDataStorageOptimizationClientException e) {
if (log.isDebugEnabled()) {
log.debug("Client error occurred while optimizing the Authentication context with " +
"context id: " + entry.getContext().getContextIdentifier(), e);
}
return;
} catch (SessionDataStorageOptimizationServerException e) {
log.error("Server error occurred while optimizing the Authentication context with " +
"context id: " + entry.getContext().getContextIdentifier(), e);
return;
} catch (SessionDataStorageOptimizationException e) {
if (log.isDebugEnabled()) {
log.debug("Error occurred while optimizing the Authentication context with " +
"context id: " + entry.getContext().getContextIdentifier(), e);
}
return;
}
}
SessionDataStore.getInstance().storeSessionData(key.getContextId(), AUTHENTICATION_CONTEXT_CACHE_NAME,
entry, tenantId);
try {
AuthenticationContextLoader.getInstance().loadAuthenticationContext(entry.getContext());
} catch (SessionDataStorageOptimizationClientException e) {
if (log.isDebugEnabled()) {
log.debug("Client error occurred while loading optimized authentication context"
+ " with context id: " + entry.getContext().getContextIdentifier(), e);
}
} catch (SessionDataStorageOptimizationServerException e) {
log.error("Server error occurred while loading optimized authentication " +
"context with context id: " + entry.getContext().getContextIdentifier(), e);
} catch (SessionDataStorageOptimizationException e) {
if (log.isDebugEnabled()) {
log.debug("Error occurred while loading optimized authentication " +
"context with context id: " + entry.getContext().getContextIdentifier(), e);
}
}
}
public void addToCacheOnRead(AuthenticationContextCacheKey key, AuthenticationContextCacheEntry entry) {
public void addToCacheOnRead(AuthenticationContextCacheKey key, AuthenticationContextCacheEntry entry) {
log.debug("Adding authentication context to cache on read for context id: " + key.getContextId());
super.addToCacheOnRead(key, entry);

Comment on lines +205 to +208
return;
}
}
SessionDataStore.getInstance().storeSessionData(key.getContextId(), AUTHENTICATION_CONTEXT_CACHE_NAME,
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.

Log Improvement Suggestion No: 16

Suggested change
return;
}
}
SessionDataStore.getInstance().storeSessionData(key.getContextId(), AUTHENTICATION_CONTEXT_CACHE_NAME,
return;
}
}
log.debug(logPrefix + "Storing session data for context id: " + key.getContextId() + ", tenant id: " + tenantId);
SessionDataStore.getInstance().storeSessionData(key.getContextId(), AUTHENTICATION_CONTEXT_CACHE_NAME,
entry, tenantId);

* @param key Key which the cache entry is indexed by.
* @param entry Value to be stored in the cache.
*/
public void addToCacheOnRead(AuthenticationErrorCacheKey key, AuthenticationErrorCacheEntry entry) {
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.

Log Improvement Suggestion No: 17

Suggested change
public void addToCacheOnRead(AuthenticationErrorCacheKey key, AuthenticationErrorCacheEntry entry) {
public void addToCacheOnRead(AuthenticationErrorCacheKey key, AuthenticationErrorCacheEntry entry) {
if (log.isDebugEnabled()) {
log.debug("Adding authentication error cache entry on read for key: " + key.getErrorKey());
}

tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
}
}
SessionDataStore.getInstance().storeSessionData(key.getErrorKey(), CACHE_NAME, entry, tenantId);
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.

Log Improvement Suggestion No: 18

Suggested change
SessionDataStore.getInstance().storeSessionData(key.getErrorKey(), CACHE_NAME, entry, tenantId);
SessionDataStore.getInstance().storeSessionData(key.getErrorKey(), CACHE_NAME, entry, tenantId);
if (log.isDebugEnabled()) {
log.debug("Persisted authentication error cache entry to session data store for tenant: " + tenantId);
}

Comment on lines +98 to +99
public void addToCacheOnRead(AuthenticationRequestCacheKey key, AuthenticationRequestCacheEntry entry) {
super.addToCacheOnRead(key, entry);
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.

Log Improvement Suggestion No: 19

Suggested change
public void addToCacheOnRead(AuthenticationRequestCacheKey key, AuthenticationRequestCacheEntry entry) {
super.addToCacheOnRead(key, entry);
public void addToCacheOnRead(AuthenticationRequestCacheKey key, AuthenticationRequestCacheEntry entry) {
if (log.isDebugEnabled()) {
log.debug("Adding authentication request to cache on read for key: " + key.getResultId());
}
super.addToCacheOnRead(key, entry);

Comment on lines +106 to +107
SessionDataStore.getInstance().storeSessionData(key.getResultId(), AUTHENTICATION_REQUEST_CACHE_NAME,
entry, tenantId);
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.

Log Improvement Suggestion No: 20

Suggested change
SessionDataStore.getInstance().storeSessionData(key.getResultId(), AUTHENTICATION_REQUEST_CACHE_NAME,
entry, tenantId);
SessionDataStore.getInstance().storeSessionData(key.getResultId(), AUTHENTICATION_REQUEST_CACHE_NAME,
entry, tenantId);
if (log.isDebugEnabled()) {
log.debug("Stored authentication request in session data store for tenant: " + tenantDomain);
}

Comment on lines +102 to +105
public void addToCacheOnRead(AuthenticationResultCacheKey key, AuthenticationResultCacheEntry entry) {
super.addToCacheOnRead(key, entry);
if (isTemporarySessionDataPersistEnabled) {
int tenantId = MultitenantConstants.INVALID_TENANT_ID;
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.

Log Improvement Suggestion No: 21

Suggested change
public void addToCacheOnRead(AuthenticationResultCacheKey key, AuthenticationResultCacheEntry entry) {
super.addToCacheOnRead(key, entry);
if (isTemporarySessionDataPersistEnabled) {
int tenantId = MultitenantConstants.INVALID_TENANT_ID;
public void addToCacheOnRead(AuthenticationResultCacheKey key, AuthenticationResultCacheEntry entry) {
if (log.isDebugEnabled()) {
log.debug("Adding authentication result to cache on read for key: " + key.getResultId());
}
super.addToCacheOnRead(key, entry);
if (isTemporarySessionDataPersistEnabled) {

Comment on lines +111 to +114
}
SessionDataStore.getInstance().storeSessionData(key.getResultId(), CACHE_NAME, entry, tenantId);
}
}
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.

Log Improvement Suggestion No: 22

Suggested change
}
SessionDataStore.getInstance().storeSessionData(key.getResultId(), CACHE_NAME, entry, tenantId);
}
}
}
SessionDataStore.getInstance().storeSessionData(key.getResultId(), CACHE_NAME, entry, tenantId);
if (log.isDebugEnabled()) {
log.debug("Stored authentication result in session data store for tenant: " + tenantId);
}
}
}

Comment on lines +50 to +54
@Override
public void addToCacheOnRead(LongWaitResultCacheKey key, LongWaitResultCacheEntry entry) {

super.addToCacheOnRead(key, entry);
}
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.

Log Improvement Suggestion No: 23

Suggested change
@Override
public void addToCacheOnRead(LongWaitResultCacheKey key, LongWaitResultCacheEntry entry) {
super.addToCacheOnRead(key, entry);
}
@Override
public void addToCacheOnRead(LongWaitResultCacheKey key, LongWaitResultCacheEntry entry) {
if (log.isDebugEnabled()) {
log.debug("Adding long wait result to cache on read for key: " + key.getHashCode());
}
super.addToCacheOnRead(key, entry);
}

Comment on lines +111 to +112
*/
private void optimizeAndStoreSessionData(SessionContextCacheKey key, SessionContextCacheEntry entry) {
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.

Log Improvement Suggestion No: 24

Suggested change
*/
private void optimizeAndStoreSessionData(SessionContextCacheKey key, SessionContextCacheEntry entry) {
private void optimizeAndStoreSessionData(SessionContextCacheKey key, SessionContextCacheEntry entry) {
if (log.isDebugEnabled()) {
log.debug("Optimizing and storing session data for context: " + key.getContextId());
}

Comment on lines 81 to +82
LongWaitResultCacheEntry cacheEntry = new LongWaitResultCacheEntry(status);
LongWaitResultCache.getInstance().addToCache(cacheKey, cacheEntry);
LongWaitResultCache.getInstance().addToCacheOnRead(cacheKey, cacheEntry);
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.

Log Improvement Suggestion No: 26

Suggested change
LongWaitResultCacheEntry cacheEntry = new LongWaitResultCacheEntry(status);
LongWaitResultCache.getInstance().addToCache(cacheKey, cacheEntry);
LongWaitResultCache.getInstance().addToCacheOnRead(cacheKey, cacheEntry);
LongWaitResultCacheEntry cacheEntry = new LongWaitResultCacheEntry(status);
log.debug("Adding wait status to cache for waitKey: {}", waitKey);
LongWaitResultCache.getInstance().addToCacheOnRead(cacheKey, cacheEntry);

Comment on lines +66 to +68
public void addToCacheOnRead(String key, IdentityMessageContext context) {
super.addToCacheOnRead(key, context);
if (enableRequestScopeCache) {
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.

Log Improvement Suggestion No: 27

Suggested change
public void addToCacheOnRead(String key, IdentityMessageContext context) {
super.addToCacheOnRead(key, context);
if (enableRequestScopeCache) {
public void addToCacheOnRead(String key, IdentityMessageContext context) {
if (log.isDebugEnabled()) {
log.debug("Adding identity context to cache on read for key: " + key);
}
super.addToCacheOnRead(key, context);

Comment on lines +74 to +75
SessionDataStore.getInstance().storeSessionData(key, INBOUND_CONTEXT_CACHE_NAME, context, tenantId);
}
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.

Log Improvement Suggestion No: 28

Suggested change
SessionDataStore.getInstance().storeSessionData(key, INBOUND_CONTEXT_CACHE_NAME, context, tenantId);
}
SessionDataStore.getInstance().storeSessionData(key, INBOUND_CONTEXT_CACHE_NAME, context, tenantId);
if (log.isDebugEnabled()) {
log.debug("Stored identity context in session data store for tenant: " + tenantDomain);
}
}

Comment on lines 1292 to +1293
cacheEntry.setContext(sessionContext);
SessionContextCache.getInstance().addToCache(cacheKey, cacheEntry);
SessionContextCache.getInstance().addToCache(cacheKey, cacheEntry, getLoginTenantDomainFromContext());
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.

Log Improvement Suggestion No: 29

Suggested change
cacheEntry.setContext(sessionContext);
SessionContextCache.getInstance().addToCache(cacheKey, cacheEntry);
SessionContextCache.getInstance().addToCache(cacheKey, cacheEntry, getLoginTenantDomainFromContext());
cacheEntry.setContext(sessionContext);
if (log.isDebugEnabled()) {
log.debug("Adding session context to cache for key: " + cacheKey.getContextId());
}

* Expects entry to be stored in SessionDataStore with a tenant ID.
*/
@Test
public void testAddToCacheOnReadWithAuthenticatedUser() {
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.

Log Improvement Suggestion No: 30

Suggested change
public void testAddToCacheOnReadWithAuthenticatedUser() {
@Test
public void testAddToCacheOnReadWithAuthenticatedUser() {
log.info("Testing addToCacheOnRead with authenticated user for context: {}", CONTEXT_ID);

/**
* Test addToCacheOnRead – SessionContextLoader throws SessionDataStorageOptimizationClientException.
* Method should return early without calling SessionDataStore.
*/
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.

Log Improvement Suggestion No: 31

Suggested change
*/
@Test
public void testAddToCacheOnReadClientExceptionReturnEarly() {
log.info("Testing addToCacheOnRead with client exception scenario");

@@ -127,7 +127,7 @@ public List<LocalClaim> getLocalClaims(int tenantId) throws ClaimMetadataExcepti
log.debug("Cache miss for local claim list for tenant: " + tenantId);
}
localClaimList = super.getLocalClaims(tenantId);
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.

Log Improvement Suggestion No: 32

Suggested change
localClaimList = super.getLocalClaims(tenantId);
localClaimList = super.getLocalClaims(tenantId);
if (log.isDebugEnabled()) {
log.debug("Retrieved " + localClaimList.size() + " local claims from database for tenant: " + tenantId);
}

@@ -211,7 +211,7 @@ public List<ExternalClaim> getExternalClaims(String externalClaimDialectURI, int
tenantId);
}
externalClaimList = super.getExternalClaims(externalClaimDialectURI, tenantId);
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.

Log Improvement Suggestion No: 33

Suggested change
externalClaimList = super.getExternalClaims(externalClaimDialectURI, tenantId);
externalClaimList = super.getExternalClaims(externalClaimDialectURI, tenantId);
if (log.isDebugEnabled()) {
log.debug("Retrieved " + externalClaimList.size() + " external claims from database for dialect: " + externalClaimDialectURI + " in tenant: " + tenantId);
}

Comment on lines +58 to +61
public void putClaimDialectsOnRead(int tenantId, List<ClaimDialect> claimDialectList) {

super.addToCacheOnRead(tenantId, (Serializable) claimDialectList, tenantId);
}
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.

Log Improvement Suggestion No: 34

Suggested change
public void putClaimDialectsOnRead(int tenantId, List<ClaimDialect> claimDialectList) {
super.addToCacheOnRead(tenantId, (Serializable) claimDialectList, tenantId);
}
public void putClaimDialectsOnRead(int tenantId, List<ClaimDialect> claimDialectList) {
if (log.isDebugEnabled()) {
log.debug("Adding claim dialects to cache on read for tenant: " + tenantId);
}
super.addToCacheOnRead(tenantId, (Serializable) claimDialectList, tenantId);
}

Comment on lines +43 to +46
public void putClaimDialectsOnRead(int tenantId, List<ClaimDialect> claimDialectList) {

super.addToCacheOnRead(tenantId, (Serializable) claimDialectList, tenantId);
}
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.

Log Improvement Suggestion No: 35

Suggested change
public void putClaimDialectsOnRead(int tenantId, List<ClaimDialect> claimDialectList) {
super.addToCacheOnRead(tenantId, (Serializable) claimDialectList, tenantId);
}
public void putClaimDialectsOnRead(int tenantId, List<ClaimDialect> claimDialectList) {
if (log.isDebugEnabled()) {
log.debug("Caching claim dialects for tenant: " + tenantId + ", dialect count: " +
(claimDialectList != null ? claimDialectList.size() : 0));
}
super.addToCacheOnRead(tenantId, (Serializable) claimDialectList, tenantId);
}

Copy link
Copy Markdown
Contributor

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

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

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1
#### Log Improvement Suggestion No: 2
#### Log Improvement Suggestion No: 3
#### Log Improvement Suggestion No: 4
#### Log Improvement Suggestion No: 5
#### Log Improvement Suggestion No: 6
#### Log Improvement Suggestion No: 7
#### Log Improvement Suggestion No: 8
#### Log Improvement Suggestion No: 9
#### Log Improvement Suggestion No: 11
#### Log Improvement Suggestion No: 13
#### Log Improvement Suggestion No: 14
#### Log Improvement Suggestion No: 15
#### Log Improvement Suggestion No: 16
#### Log Improvement Suggestion No: 17
#### Log Improvement Suggestion No: 18
#### Log Improvement Suggestion No: 19
#### Log Improvement Suggestion No: 20
#### Log Improvement Suggestion No: 21
#### Log Improvement Suggestion No: 22
#### Log Improvement Suggestion No: 23
#### Log Improvement Suggestion No: 24
#### Log Improvement Suggestion No: 26
#### Log Improvement Suggestion No: 27
#### Log Improvement Suggestion No: 28
#### Log Improvement Suggestion No: 29
#### Log Improvement Suggestion No: 30
#### Log Improvement Suggestion No: 31
#### Log Improvement Suggestion No: 32
#### Log Improvement Suggestion No: 33
#### Log Improvement Suggestion No: 34
#### Log Improvement Suggestion No: 35

@sonarqubecloud
Copy link
Copy Markdown

@jenkins-is-staging
Copy link
Copy Markdown

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

@jenkins-is-staging
Copy link
Copy Markdown

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

@ThaminduR ThaminduR merged commit bfa9965 into next Mar 26, 2026
2 checks passed
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.

3 participants