Skip to content

Commit

Permalink
Updated cache_prefix to cache_suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj-Shah1 committed Sep 13, 2023
1 parent 846e9c4 commit 7dbee79
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
4 changes: 3 additions & 1 deletion sample.secrets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
"ERROR_MAIL_FROM": "",
"ERROR_MAIL_TO": "",
"COOKIE_DOMAIN": "",
"OPENAI_API_KEY": ""
"OPENAI_API_KEY": "",
"DEFAULT_TEST_USER":"",
"DEFAULT_TEST_USER_PASSWORD":""
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
@Component
public class CacheConstants {

public static final String CACHE_PREFIX;
public static final String CACHE_SUFFIX;

static {
if (CoreConstants.isProductionEnvironment()) {
CACHE_PREFIX = "prod_";
CACHE_SUFFIX = "_prod";
}
else if (CoreConstants.isStagingEnvironment()) {
CACHE_PREFIX = "stag_";
CACHE_SUFFIX = "_stag";
}
else if (CoreConstants.isTestEnvironment()) {
CACHE_PREFIX = "test_";
CACHE_SUFFIX = "_test";
}
else if (CoreConstants.isLocalTestEnvironment()) {
CACHE_PREFIX = "ltest_";
CACHE_SUFFIX = "_ltest";
}
else {
CACHE_PREFIX = "dev_";
CACHE_SUFFIX = "_dev";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public SalesforceOauthTokenRepository(DynamoDBMapper dynamoDBMapper) {
* @return SalesforceOauthToken
*/
@CacheEvict(value = CacheConstants.SALESFORCE_OAUTH_TOKEN_CACHE,
key = "T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_PREFIX + #salesforceOauthToken.externalUserId")
key = "#salesforceOauthToken.externalUserId + T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_SUFFIX")
public SalesforceOauthToken createSalesforceOauthToken(SalesforceOauthToken salesforceOauthToken) {
// Create a row with status active and created at as current time
salesforceOauthToken.setStatus(SalesforceOauthToken.Status.ACTIVE);
Expand All @@ -50,7 +50,7 @@ public SalesforceOauthToken createSalesforceOauthToken(SalesforceOauthToken sale
* @return SalesforceOauthToken
*/
@CacheEvict(value = CacheConstants.SALESFORCE_OAUTH_TOKEN_CACHE,
key = "T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_PREFIX + #salesforceOauthToken.externalUserId")
key = "#salesforceOauthToken.externalUserId + T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_SUFFIX")
public SalesforceOauthToken updateSalesforceOauthToken(SalesforceOauthToken salesforceOauthToken) {
try {
dynamoDBMapper.save(salesforceOauthToken);
Expand All @@ -68,7 +68,7 @@ public SalesforceOauthToken updateSalesforceOauthToken(SalesforceOauthToken sale
* @return SalesforceOauthToken
*/
@Cacheable(value = CacheConstants.SALESFORCE_OAUTH_TOKEN_CACHE,
key = "T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_PREFIX + #externalUserId")
key = "#externalUserId + T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_SUFFIX")
public SalesforceOauthToken getSalesforceOauthTokenByExternalUserId(String externalUserId) {
try {
return dynamoDBMapper.load(SalesforceOauthToken.class, externalUserId);
Expand All @@ -85,7 +85,7 @@ public SalesforceOauthToken getSalesforceOauthTokenByExternalUserId(String exter
* @return void
*/
@CacheEvict(value = CacheConstants.SALESFORCE_OAUTH_TOKEN_CACHE,
key = "T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_PREFIX + #salesforceOauthToken.externalUserId")
key = "#salesforceOauthToken.externalUserId + T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_SUFFIX")
public void deleteSalesforceOauthTokenBySalesforceOauthToken(SalesforceOauthToken salesforceOauthToken) {
try {
dynamoDBMapper.delete(salesforceOauthToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SalesforceUserRepository(DynamoDBMapper dynamoDBMapper) {
* @return SalesforceUser
*/
@CacheEvict(value = CacheConstants.SALESFORCE_USER_CACHE,
key = "T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_PREFIX + #salesforceUser.externalUserId")
key = "#salesforceUser.externalUserId + T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_SUFFIX")
public SalesforceUser createSalesforceUser(SalesforceUser salesforceUser) {
// Create a row with status active and created at as current time
salesforceUser.setStatus(SalesforceUser.Status.ACTIVE);
Expand All @@ -51,7 +51,7 @@ public SalesforceUser createSalesforceUser(SalesforceUser salesforceUser) {
* @return SalesforceUser
*/
@CacheEvict(value = CacheConstants.SALESFORCE_USER_CACHE,
key = "T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_PREFIX + #salesforceUser.externalUserId")
key = "#salesforceUser.externalUserId + T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_SUFFIX")
public SalesforceUser updateSalesforceUser(SalesforceUser salesforceUser) {
try {
dynamoDBMapper.save(salesforceUser);
Expand All @@ -69,7 +69,7 @@ public SalesforceUser updateSalesforceUser(SalesforceUser salesforceUser) {
* @return SalesforceUser
*/
@Cacheable(value = CacheConstants.SALESFORCE_USER_CACHE,
key = "T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_PREFIX + #externalUserId")
key = "#externalUserId + T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_SUFFIX")
public SalesforceUser getSalesforceUserByExternalUserId(String externalUserId) {
try {
return dynamoDBMapper.load(SalesforceUser.class, externalUserId);
Expand All @@ -80,7 +80,7 @@ public SalesforceUser getSalesforceUserByExternalUserId(String externalUserId) {
}

@CacheEvict(value = CacheConstants.SALESFORCE_USER_CACHE,
key = "T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_PREFIX + #externalUserId")
key = "#externalUserId + T(com.salessparrow.api.lib.globalConstants.CacheConstants).CACHE_SUFFIX")
public void removeSalesforceUserData(String externalUserId) {
SalesforceUser salesforceUser = getSalesforceUserByExternalUserId(externalUserId);
salesforceUser.setIdentityUrl(null);
Expand Down

0 comments on commit 7dbee79

Please sign in to comment.