Skip to content

Commit

Permalink
Improve readability and resolve review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
subrata71 committed Sep 9, 2024
1 parent a7b066c commit 25e71b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ public interface CacheableRepositoryHelperCE {

Mono<Void> evictCachedTenant(String tenantId);

/**
* Retrieves the base application ID from the cache based on the provided base page ID.
*
* <p>If the cache contains the ID for the specified {@code basePageId}, it is returned as a {@code Mono} containing the {@code baseApplicationId}.
* If the cache does not contain the ID (cache miss) and {@code baseApplicationId} is {@code null} or empty, an empty {@code Mono} is returned.</p>
*
* <p>If {@code baseApplicationId} is not {@code null} or empty and a cache miss occurs, the cache will be updated with the provided {@code baseApplicationId}.</p>
*
* <p>Note that calling this method with a {@code null} {@code baseApplicationId} on a cache miss will not update the cache.
* In this case, the method will return an empty {@code Mono}, and no cache update will occur.</p>
*
* @param basePageId the identifier for the base page used as the cache key
* @param baseApplicationId the base application ID to be returned or used to update the cache if not {@code null} or empty
* @return a {@code Mono} containing the {@code baseApplicationId} if it is present in the cache or provided; otherwise, an empty {@code Mono} on a cache miss with a {@code null} or empty {@code baseApplicationId}.
*
* <p>On a cache miss, if {@code baseApplicationId} is provided, the cache will be updated with the new value after performing additional database operations to fetch the application document.</p>
*/
Mono<String> fetchBaseApplicationId(String basePageId, String baseApplicationId);

Mono<Boolean> evictCachedBasePageIds(List<String> basePageIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ public Mono<ConsolidatedAPIResponseDTO> getConsolidatedInfoForPageLoad(

/* Fetch default application id if not provided */
Mono<Application> branchedApplicationMonoCached;
Mono<String> baseApplicationIdMono = Mono.just("NA");
Mono<String> baseApplicationIdMono = Mono.just("");
if (isViewMode) {
// Attempt to retrieve the application ID associated with the given base page ID from the cache.
baseApplicationIdMono = cacheableRepositoryHelper
.fetchBaseApplicationId(basePageId, baseApplicationId)
.switchIfEmpty(Mono.just("NA"))
.switchIfEmpty(Mono.just(""))
.cast(String.class);
}
baseApplicationIdMono = baseApplicationIdMono
Expand All @@ -223,7 +223,7 @@ public Mono<ConsolidatedAPIResponseDTO> getConsolidatedInfoForPageLoad(
}

branchedApplicationMonoCached = baseApplicationIdMono.flatMap(cachedBaseApplicationId -> {
if (cachedBaseApplicationId.equals("NA")) {
if (!StringUtils.hasText(cachedBaseApplicationId)) {
// Handle empty or null baseApplicationId
return newPageService
.findByBranchNameAndBasePageIdAndApplicationMode(branchName, basePageId, mode)
Expand Down

0 comments on commit 25e71b5

Please sign in to comment.