From 85514506915284353d66c8df7c299ef05d3453b1 Mon Sep 17 00:00:00 2001 From: joshydavid Date: Sun, 27 Jul 2025 18:33:41 +0800 Subject: [PATCH] refactor: abstract redis cache param for code cleanliness Signed-off-by: joshydavid --- backend/src/main/java/com/bi/constant/RedisCacheKey.java | 1 + .../main/java/com/bi/service/impl/CoffeeListingServiceImpl.java | 2 +- .../src/main/java/com/bi/service/impl/RecipeServiceImpl.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/bi/constant/RedisCacheKey.java b/backend/src/main/java/com/bi/constant/RedisCacheKey.java index 7786215..b92829e 100644 --- a/backend/src/main/java/com/bi/constant/RedisCacheKey.java +++ b/backend/src/main/java/com/bi/constant/RedisCacheKey.java @@ -5,6 +5,7 @@ private RedisCacheKey() { } + public static final String CACHE_PARAM = "#userId"; public static final String GET_COFFEE_LISTINGS_KEY = "getCoffeeListings"; public static final String GET_USER_COFFEE_LISTINGS_KEY = "getUserCoffeeListings"; public static final String GET_FILTERED_COFFEE_LISTINGS_KEY = "getFilteredCoffeeListings"; diff --git a/backend/src/main/java/com/bi/service/impl/CoffeeListingServiceImpl.java b/backend/src/main/java/com/bi/service/impl/CoffeeListingServiceImpl.java index 1f5137a..787f62f 100644 --- a/backend/src/main/java/com/bi/service/impl/CoffeeListingServiceImpl.java +++ b/backend/src/main/java/com/bi/service/impl/CoffeeListingServiceImpl.java @@ -38,7 +38,7 @@ public List getCoffeeListings() { } @Override - @Cacheable(value = RedisCacheKey.GET_USER_COFFEE_LISTINGS_KEY, key = "#userId") + @Cacheable(value = RedisCacheKey.GET_USER_COFFEE_LISTINGS_KEY, key = RedisCacheKey.CACHE_PARAM) public List getCoffeeListingsByUserId(String userId) { List userCoffeeListings = this.coffeeListingRepo.findByUserProfileUserId(userId); return userCoffeeListings.stream() diff --git a/backend/src/main/java/com/bi/service/impl/RecipeServiceImpl.java b/backend/src/main/java/com/bi/service/impl/RecipeServiceImpl.java index 1700f14..013e7c0 100644 --- a/backend/src/main/java/com/bi/service/impl/RecipeServiceImpl.java +++ b/backend/src/main/java/com/bi/service/impl/RecipeServiceImpl.java @@ -37,7 +37,7 @@ public List getRecipes() { } @Override - @Cacheable(value = RedisCacheKey.GET_USER_RECIPES_KEY, key = "#userId") + @Cacheable(value = RedisCacheKey.GET_USER_RECIPES_KEY, key = RedisCacheKey.CACHE_PARAM) public List getCoffeeRecipesByUserId(String userId) { List userRecipes = this.recipeRepo.findByUserProfileUserId(userId); return userRecipes.stream()