-
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.
move eh cache directory to ${user.home}/RECOMBackend/ehcache
tidy up, did some tests, cache statistics ep
- Loading branch information
Showing
10 changed files
with
164 additions
and
21 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
29 changes: 29 additions & 0 deletions
29
libs/sharedmodels/src/main/java/com/recom/dto/cache/CacheInfoDto.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,29 @@ | ||
package com.recom.dto.cache; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Set; | ||
|
||
@Data | ||
@Schema | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class CacheInfoDto { | ||
|
||
@Schema() | ||
private String name; | ||
@Schema() | ||
private Long size; | ||
@Schema | ||
private Set<Object> keys; | ||
@Schema | ||
private String stats; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
libs/sharedmodels/src/main/java/com/recom/dto/cache/CacheStatisticsDto.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,23 @@ | ||
package com.recom.dto.cache; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Schema | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class CacheStatisticsDto { | ||
|
||
@Schema() | ||
private List<CacheInfoDto> caches; | ||
|
||
} |
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
56 changes: 56 additions & 0 deletions
56
services/recom-backend/src/main/java/com/recom/service/cache/CacheStatisticsProvider.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,56 @@ | ||
package com.recom.service.cache; | ||
|
||
import com.recom.dto.cache.CacheInfoDto; | ||
import com.recom.dto.cache.CacheStatisticsDto; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.stat.CacheRegionStatistics; | ||
import org.hibernate.stat.Statistics; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class CacheStatisticsProvider { | ||
|
||
@NonNull | ||
private final SessionFactory sessionFactory; | ||
|
||
|
||
@NonNull | ||
public CacheStatisticsDto provide() { | ||
final Statistics statistics = sessionFactory.getStatistics(); | ||
final List<CacheInfoDto> caches = Arrays.stream(statistics.getSecondLevelCacheRegionNames()) | ||
.map(region -> { | ||
try { | ||
return statistics.getDomainDataRegionStatistics(region); | ||
} catch (final Exception e) { | ||
log.warn("Error getting cache statistics for region: {}", region); | ||
return null; | ||
} | ||
}) | ||
.filter(Objects::nonNull) | ||
.map(this::getCacheInfo) | ||
.toList(); | ||
|
||
return CacheStatisticsDto.builder() | ||
.caches(caches) | ||
.build(); | ||
} | ||
|
||
@NonNull | ||
private CacheInfoDto getCacheInfo(@NonNull final CacheRegionStatistics regionStatistics) { | ||
return CacheInfoDto.builder() | ||
.name(regionStatistics.getRegionName()) | ||
.size(regionStatistics.getSizeInMemory()) | ||
.stats(regionStatistics.toString()) | ||
.build(); | ||
} | ||
|
||
} |
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
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