use ClientConfig to configure client-server Hazelcast cache
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
package io.reflectoring.cache.configiration;
|
||||
|
||||
|
||||
import com.hazelcast.client.HazelcastClient;
|
||||
import com.hazelcast.client.config.ClientConfig;
|
||||
import com.hazelcast.config.NearCacheConfig;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.spring.cache.HazelcastCacheManager;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -31,15 +27,4 @@ public class ClientCacheConfig {
|
||||
nearCacheConfig.setTimeToLiveSeconds(300);
|
||||
return nearCacheConfig;
|
||||
}
|
||||
|
||||
@Bean
|
||||
HazelcastInstance hazelcastInstance() {
|
||||
return HazelcastClient.newHazelcastClient();
|
||||
}
|
||||
|
||||
@Bean
|
||||
CacheManager cacheManager() {
|
||||
return new HazelcastCacheManager(hazelcastInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.springframework.context.annotation.Profile;
|
||||
public class EmbeddedCacheConfig {
|
||||
|
||||
@Bean
|
||||
Config config(){
|
||||
Config config() {
|
||||
Config config = new Config();
|
||||
|
||||
MapConfig mapConfig = new MapConfig();
|
||||
@@ -24,5 +24,4 @@ public class EmbeddedCacheConfig {
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.reflectoring.cache.service;
|
||||
|
||||
import io.reflectoring.cache.dao.Car;
|
||||
import io.reflectoring.cache.dao.CarRepository;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
@@ -13,9 +14,11 @@ import java.util.UUID;
|
||||
public class CarService {
|
||||
|
||||
private final CarRepository carRepository;
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
public CarService(CarRepository carRepository) {
|
||||
public CarService(CarRepository carRepository, CacheManager cacheManager) {
|
||||
this.carRepository = carRepository;
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
public Car saveCar(Car car) {
|
||||
|
||||
Reference in New Issue
Block a user