Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

[DPG-1388]-implemented-redis-caching #164

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions business-services/dashboard-analytics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand All @@ -16,11 +22,13 @@

import com.tarento.analytics.constant.Constants;

import java.time.Duration;
import java.util.concurrent.TimeUnit;


@SpringBootApplication
@EnableCaching
@ComponentScan(basePackages = {"com.tarento.analytics"})
public class AnalyticApp {
public static void main( String[] args ) {
SpringApplication.run(AnalyticApp.class, args);
Expand Down Expand Up @@ -48,11 +56,15 @@ public void addCorsMappings(CorsRegistry registry) {
};
}

@Bean
@Profile("!test")
public CacheManager cacheManager(){
return new SpringCache2kCacheManager().addCaches(b->b.name("versions").expireAfterWrite(cacheExpiry, TimeUnit.MINUTES)
.entryCapacity(cacheCapacity));
}
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(5)) // set TTL to 5 minutes
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));

return RedisCacheManager.builder(redisConnectionFactory)
.cacheDefaults(cacheConfiguration)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public class Data {
private String headerName;
private Object headerValue;
private String headerSymbol;
private InsightsWidget insight;

private InsightsWidget insight;

public Data() {
}
public InsightsWidget getInsight() {
return insight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Plot {
private String strValue;
private String symbol;

public Plot(){
}
public Plot(String name, Double value, String symbol) {
this.name = name;
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.tarento.analytics.handler.ResponseHandlerFactory;
import com.tarento.analytics.service.QueryService;
import com.tarento.analytics.service.impl.RestService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -23,6 +24,7 @@
import java.util.List;
import java.util.Map;

@Slf4j
@Component
public class MdmsServiceImpl implements ClientService {

Expand All @@ -48,6 +50,7 @@ public class MdmsServiceImpl implements ClientService {
@Override
@Cacheable(value="versions", key="#request.hashKey")
public AggregateDto getAggregatedData(AggregateRequestDto request, List<RoleDto> roles) throws AINException, IOException {
log.info("This data is cached from Database");
// Read visualization Code
String chartId = request.getVisualizationCode();
logger.info("chartId >> "+chartId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -37,7 +38,7 @@
import com.tarento.analytics.service.impl.RestService;
import com.tarento.analytics.utils.ResponseRecorder;


@Slf4j
@Component
public class TarentoServiceImpl implements ClientService {

Expand Down Expand Up @@ -68,6 +69,7 @@ public class TarentoServiceImpl implements ClientService {
@Override
@Cacheable(value="versions", key="#request.hashKey")
public AggregateDto getAggregatedData(AggregateRequestDto request, List<RoleDto> roles) throws AINException, IOException {
log.info("This data is cached from Database");
// Read visualization Code
String internalChartId = request.getVisualizationCode();
ObjectNode aggrObjectNode = JsonNodeFactory.instance.objectNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ filename.length=10
filename.useletters=true
filename.usenumbers=false

# CACHE CONFIG
spring.redis.host=localhost
spring.redis.port=6379

cache.expiry.time.in.minutes=10
cache.capacity=120

Expand Down
Loading