forked from mosip/id-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sohan Kumar Dey <[email protected]>
- Loading branch information
Showing
10 changed files
with
238 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 81 additions & 91 deletions
172
...java/io/mosip/credential/request/generator/service/impl/CredentialRequestServiceImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...request-generator/src/main/java/io/mosip/credential/request/generator/util/CacheUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.mosip.credential.request.generator.util; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.annotation.CachePut; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Service; | ||
|
||
import io.mosip.credential.request.generator.entity.CredentialEntity; | ||
import io.mosip.idrepository.core.dto.CredentialIssueStatusResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Service | ||
public class CacheUtil { | ||
|
||
@Autowired | ||
CacheManager cacheManager; | ||
|
||
|
||
@Cacheable(value = "credential_transaction", key = "#requestId") | ||
public CredentialIssueStatusResponse setCredentialTransaction(String requestId, CredentialEntity credentialEntity, String id) { | ||
|
||
return createCredentialIssueStatusResponse(requestId, credentialEntity, id); | ||
} | ||
|
||
@CachePut(value = "credential_transaction", key = "#requestId") | ||
public CredentialIssueStatusResponse updateCredentialTransaction(String requestId, CredentialEntity credentialEntity, String id) { | ||
|
||
return createCredentialIssueStatusResponse(requestId, credentialEntity, id); | ||
} | ||
|
||
|
||
public CredentialIssueStatusResponse createCredentialIssueStatusResponse(String requestId, CredentialEntity credentialEntity, String id) { | ||
CredentialIssueStatusResponse credentialIssueStatusResponse = new CredentialIssueStatusResponse(); | ||
credentialIssueStatusResponse.setId(id); | ||
credentialIssueStatusResponse.setRequestId(requestId); | ||
credentialIssueStatusResponse.setStatusCode(credentialEntity.getStatusCode()); | ||
credentialIssueStatusResponse.setUrl(credentialEntity.getDataShareUrl()); | ||
return credentialIssueStatusResponse; | ||
} | ||
|
||
public CredentialIssueStatusResponse getCredentialTransaction(String requestId) { | ||
return cacheManager.getCache("credential_transaction").get(requestId, CredentialIssueStatusResponse.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../id-repository-core/src/main/java/io/mosip/idrepository/core/config/RedisCacheConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.mosip.idrepository.core.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
import org.springframework.data.redis.cache.RedisCacheManager; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
|
||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@ConditionalOnProperty(value = "spring.cache.type", havingValue = "redis") | ||
@Configuration | ||
public class RedisCacheConfig { | ||
|
||
@Value("${mosip.credential.cache.expire-in-seconds:60}") | ||
private Integer cacheExpireInSeconds; | ||
|
||
@Bean | ||
public CacheManager cacheManager(RedisConnectionFactory connectionFactory) { | ||
Map<String, RedisCacheConfiguration> cacheConfigurations = new HashMap<>(); | ||
cacheConfigurations.put("credential_transaction", RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(cacheExpireInSeconds))); | ||
|
||
return RedisCacheManager.builder(connectionFactory) | ||
.withInitialCacheConfigurations(cacheConfigurations) | ||
.build(); | ||
} | ||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...id-repository-core/src/main/java/io/mosip/idrepository/core/config/SimpleCacheConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.mosip.idrepository.core.config; | ||
|
||
import java.util.Arrays; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.annotation.CachingConfigurerSupport; | ||
import org.springframework.cache.concurrent.ConcurrentMapCache; | ||
import org.springframework.cache.support.SimpleCacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.google.common.cache.CacheBuilder; | ||
|
||
@ConditionalOnProperty(value = "spring.cache.type", havingValue = "simple", matchIfMissing = true) | ||
@Configuration | ||
public class SimpleCacheConfig extends CachingConfigurerSupport { | ||
|
||
@Value("${mosip.credential.cache.size:100}") | ||
private Integer cacheMaxSize; | ||
|
||
@Value("${mosip.credential.cache.expire-in-seconds:60}") | ||
private Integer cacheExpireInSeconds; | ||
|
||
|
||
@Bean | ||
@Override | ||
public CacheManager cacheManager() { | ||
SimpleCacheManager cacheManager = new SimpleCacheManager(); | ||
cacheManager.setCaches(Arrays.asList(buildMapCache("credential_transaction"))); | ||
return cacheManager; | ||
} | ||
|
||
private ConcurrentMapCache buildMapCache(String name) { | ||
return new ConcurrentMapCache(name, | ||
CacheBuilder.newBuilder() | ||
.expireAfterWrite(cacheExpireInSeconds, TimeUnit.SECONDS) | ||
.maximumSize(cacheMaxSize) | ||
.build() | ||
.asMap(), true); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters