Skip to content

Commit

Permalink
add one and multiple key Application Caches + config
Browse files Browse the repository at this point in the history
  • Loading branch information
svencc committed Apr 14, 2024
1 parent 30b6a4e commit 06dd07b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ public ResponseEntity<List<CacheStatisticsDto>> testAppCache() {
log.debug("Requested GET /api/v1/cache/test-app-cache");

final CacheStatisticsDto testWithoutKey = applicationCacheTester.testWithoutKey();
// final CacheStatisticsDto testWithOneKey = applicationCacheTester.testWithOneKey("key1");
// final CacheStatisticsDto testWithMultipleKEys = applicationCacheTester.testWithMultipleKeys("key1", "key2");
for (int i = 0; i < 1000; i++) {
applicationCacheTester.testWithOneKey("key" + i);
applicationCacheTester.testWithMultipleKeys("key1" + i, "key2" + i);
}

return ResponseEntity.status(HttpStatus.OK)
.cacheControl(CacheControl.noCache())
.body(List.of(testWithoutKey));
// .body(List.of(testWithoutKey, testWithOneKey, testWithMultipleKEys));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.jsr107.Eh107Configuration;
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
import org.springframework.cache.interceptor.SimpleKey;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand Down Expand Up @@ -52,7 +53,9 @@ private void addCaches(@NotNull final CacheManager eh107CacheManager) {


private void addEHCaches(@NotNull final CacheManager eh107CacheManager) {
final Cache<Object, CacheStatisticsDto> myCache = eh107CacheManager.createCache("com.recom.service.cache.ApplicationCacheTester.testWithoutKey()", Eh107Configuration.fromEhcacheCacheConfiguration(applicationEHCacheConfiguration(Object.class, CacheStatisticsDto.class)));
eh107CacheManager.createCache("com.recom.service.cache.ApplicationCacheTester.testWithoutKey", Eh107Configuration.fromEhcacheCacheConfiguration(applicationEHCacheConfiguration(Object.class, CacheStatisticsDto.class)));
eh107CacheManager.createCache("com.recom.service.cache.ApplicationCacheTester.testWithOneKey", Eh107Configuration.fromEhcacheCacheConfiguration(applicationEHCacheConfiguration(String.class, CacheStatisticsDto.class)));
eh107CacheManager.createCache("com.recom.service.cache.ApplicationCacheTester.testWithMultipleKeys", Eh107Configuration.fromEhcacheCacheConfiguration(applicationEHCacheConfiguration(SimpleKey.class, CacheStatisticsDto.class)));
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class ApplicationCacheTester {

@NonNull
@CacheResult
@CacheResult(cacheName = "com.recom.service.cache.ApplicationCacheTester.testWithoutKey")
public CacheStatisticsDto testWithoutKey() {
return CacheStatisticsDto.builder()
.caches(List.of(
Expand All @@ -31,36 +31,36 @@ public CacheStatisticsDto testWithoutKey() {
))
.build();
}
//
// @NonNull
// @CacheResult()
// public CacheStatisticsDto testWithOneKey(@NonNull final String key) {
// return CacheStatisticsDto.builder()
// .caches(List.of(
// CacheInfoDto.builder()
// .name("test-with-one-key: " + key)
// .size(1L)
// .stats("test")
// .build()
// ))
// .build();
// }
//
// @NonNull
// @CacheResult
// public CacheStatisticsDto testWithMultipleKeys(
// @NonNull final String key1,
// @NonNull final String key2
// ) {
// return CacheStatisticsDto.builder()
// .caches(List.of(
// CacheInfoDto.builder()
// .name("test-with-multiple-keys: " + key1 + ", " + key2)
// .size(1L)
// .stats("test")
// .build()
// ))
// .build();
// }

@NonNull
@CacheResult(cacheName = "com.recom.service.cache.ApplicationCacheTester.testWithOneKey")
public CacheStatisticsDto testWithOneKey(@NonNull final String key) {
return CacheStatisticsDto.builder()
.caches(List.of(
CacheInfoDto.builder()
.name("test-with-one-key: " + key)
.size(1L)
.stats("test")
.build()
))
.build();
}

@NonNull
@CacheResult(cacheName = "com.recom.service.cache.ApplicationCacheTester.testWithMultipleKeys")
public CacheStatisticsDto testWithMultipleKeys(
@NonNull final String key1,
@NonNull final String key2
) {
return CacheStatisticsDto.builder()
.caches(List.of(
CacheInfoDto.builder()
.name("test-with-multiple-keys: " + key1 + ", " + key2)
.size(1L)
.stats("test")
.build()
))
.build();
}

}

0 comments on commit 06dd07b

Please sign in to comment.