diff --git a/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java b/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java index 44a25c20112f27d83e104e2988715fbe6162979c..d5a897da4212d9d53ae2bd26e0ae4fcf822fc110 100644 --- a/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java +++ b/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java @@ -50,6 +50,7 @@ public class CachedPartitionServiceImpl implements IPartitionService { if (pi != null) { partitionServiceCache.put(partitionId, partitionInfo); + partitionListCache.clearAll(); } return pi; @@ -86,6 +87,7 @@ public class CachedPartitionServiceImpl implements IPartitionService { if (partitionService.deletePartition(partitionId)) { if (partitionServiceCache.get(partitionId) != null) { partitionServiceCache.delete(partitionId); + partitionListCache.clearAll(); } return true; diff --git a/partition-core/src/test/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImplTest.java b/partition-core/src/test/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImplTest.java index 596dac8ddf2fd949da61196d990513d3a860b1df..7d2680573eaa08e0e471c186603052320e042400 100644 --- a/partition-core/src/test/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImplTest.java +++ b/partition-core/src/test/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImplTest.java @@ -52,11 +52,11 @@ public class CachedPartitionServiceImplTest { PartitionInfo retPi = PartitionInfo.builder().build(); when(partitionServiceImpl.createPartition(partId, newPi)).thenReturn(retPi); - cachedPartitionServiceImpl.createPartition(partId, newPi); verify(partitionServiceImpl, times(1)).createPartition(partId, newPi); verify(partitionServiceCache, times(1)).put(partId, retPi); + verify(partitionListCache, times(1)).clearAll(); } @Test @@ -71,6 +71,7 @@ public class CachedPartitionServiceImplTest { verify(partitionServiceImpl, times(1)).createPartition(partId, newPi); verify(partitionServiceCache, times(0)).put(any(), any()); + verify(partitionListCache, times(0)).clearAll(); verify(partitionServiceCache, times(1)).get(any()); } @@ -131,6 +132,7 @@ public class CachedPartitionServiceImplTest { verify(partitionServiceImpl, times(1)).deletePartition(partId); verify(partitionServiceCache, times(1)).delete(partId); verify(partitionServiceCache, times(1)).get(partId); + verify(partitionListCache, times(1)).clearAll(); } @Test diff --git a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/RedisConfig.java b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/RedisConfig.java index 627ae0a70c3250f345a387dd144bd8bb2745de89..5aa7bc6ea5318b45f563c637f79b15285b321014 100644 --- a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/RedisConfig.java +++ b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/RedisConfig.java @@ -10,6 +10,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.inject.Named; +import java.util.List; @Configuration public class RedisConfig { @@ -44,6 +45,11 @@ public class RedisConfig { return new RedisCache<>(host, port, password, expiration, database, String.class, PartitionInfo.class); } + @Bean + public RedisCache<String, List<String>> partitionListCache(@Named("REDIS_HOST") String host, @Named("REDIS_PASSWORD") String password) { + return new RedisCache(host, port, password, expiration, database, String.class, List.class); + } + } @Configuration @@ -64,5 +70,10 @@ public class RedisConfig { return new RedisCache<>(host, port, expiration, database, String.class, PartitionInfo.class); } + @Bean + public RedisCache<String, List<String>> partitionListCache(@Named("REDIS_HOST") String host) { + return new RedisCache(host, port, expiration, database, String.class, List.class); + } + } } diff --git a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/VmConfig.java b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/VmConfig.java index 00aef74c5f3649d73844d245967c933d692fabdb..93c885fe368d1787a90669f4d2a3598ba60e7f56 100644 --- a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/VmConfig.java +++ b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/VmConfig.java @@ -1,6 +1,7 @@ package org.opengroup.osdu.partition.provider.azure.di; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.partition.model.PartitionInfo; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; @@ -12,6 +13,7 @@ import java.util.List; public class VmConfig { @Bean + @ConditionalOnProperty(value = "cache.provider", havingValue = "vm", matchIfMissing = true) public VmCache<String, List<String>> partitionListCache(@Value("${cache.expiration}") final int expiration, @Value("${cache.maxSize}") final int maxSize) { return new VmCache<>(expiration * 60, maxSize); @@ -19,8 +21,8 @@ public class VmConfig { @Bean @ConditionalOnProperty(value = "cache.provider", havingValue = "vm", matchIfMissing = true) - public VmCache<String, List<String>> partitionServiceCache(@Value("${cache.expiration}") final int expiration, - @Value("${cache.maxSize}") final int maxSize) { + public VmCache<String, PartitionInfo> partitionServiceCache(@Value("${cache.expiration}") final int expiration, + @Value("${cache.maxSize}") final int maxSize) { return new VmCache<>(expiration * 60, maxSize); } }