Skip to content

Commit fa53509

Browse files
author
akuksin
committed
clean up
1 parent 2273d59 commit fa53509

5 files changed

Lines changed: 13 additions & 207 deletions

File tree

spring-boot/cache/gradlew

Lines changed: 1 addition & 184 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring-boot/cache/src/main/java/io/reflectoring/cache/configiration/ClientCacheConfig.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import com.hazelcast.client.HazelcastClient;
55
import com.hazelcast.client.config.ClientConfig;
6-
import com.hazelcast.config.MapConfig;
6+
import com.hazelcast.config.NearCacheConfig;
77
import com.hazelcast.core.HazelcastInstance;
88
import com.hazelcast.spring.cache.HazelcastCacheManager;
99
import org.springframework.cache.CacheManager;
@@ -21,12 +21,17 @@ public class ClientCacheConfig {
2121
@Bean
2222
ClientConfig config() {
2323
ClientConfig clientConfig = new ClientConfig();
24-
25-
MapConfig mapConfig = new MapConfig();
26-
mapConfig.setTimeToLiveSeconds(300);
24+
clientConfig.addNearCacheConfig(nearCacheConfig());
2725
return clientConfig;
2826
}
2927

28+
private NearCacheConfig nearCacheConfig() {
29+
NearCacheConfig nearCacheConfig = new NearCacheConfig();
30+
nearCacheConfig.setName("cars");
31+
nearCacheConfig.setTimeToLiveSeconds(300);
32+
return nearCacheConfig;
33+
}
34+
3035
@Bean
3136
HazelcastInstance hazelcastInstance() {
3237
return HazelcastClient.newHazelcastClient();

spring-boot/cache/src/main/java/io/reflectoring/cache/configiration/EmbeddedCacheConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
@Configuration
1313
@EnableCaching
1414
@Profile("embedded")
15-
public class EmbeddedCacheConfig /*extends CachingConfigurerSupport*/ {
15+
public class EmbeddedCacheConfig {
1616

1717
@Bean
1818
Config config(){
1919
Config config = new Config();
2020

2121
MapConfig mapConfig = new MapConfig();
2222
mapConfig.setTimeToLiveSeconds(300);
23-
//mapConfig.setMaxIdleSeconds(10);
24-
2523
config.getMapConfigs().put("cars", mapConfig);
24+
2625
return config;
2726
}
2827

spring-boot/cache/src/main/java/io/reflectoring/cache/rest/CarResource.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ private CarDto createCar(@RequestBody CarDto carDto) {
3333

3434
@PutMapping
3535
private CarDto updateCar(@RequestBody CarDto carDto) {
36-
if (carDto.getId() == null){
37-
// TODO add exception handler to return 400
38-
throw new IllegalArgumentException("A car must have an id to be updated.");
39-
}
4036
Car car = carMapper.toCar(carDto);
4137
return carMapper.toCarDto(carService.update(car));
4238
}

spring-boot/cache/src/main/java/io/reflectoring/cache/service/CarService.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.reflectoring.cache.dao.Car;
44
import io.reflectoring.cache.dao.CarRepository;
5-
import org.springframework.cache.CacheManager;
65
import org.springframework.cache.annotation.CacheEvict;
76
import org.springframework.cache.annotation.CachePut;
87
import org.springframework.cache.annotation.Cacheable;
@@ -14,11 +13,9 @@
1413
public class CarService {
1514

1615
private final CarRepository carRepository;
17-
private final CacheManager cacheManager;
1816

19-
public CarService(CarRepository carRepository, CacheManager cacheManager) {
17+
public CarService(CarRepository carRepository) {
2018
this.carRepository = carRepository;
21-
this.cacheManager = cacheManager;
2219
}
2320

2421
public Car saveCar(Car car) {
@@ -30,7 +27,6 @@ public Car update(Car car) {
3027
if (carRepository.existsById(car.getId())) {
3128
return carRepository.save(car);
3229
}
33-
// TODO add an exception handle and a dedicated exception
3430
throw new IllegalArgumentException("A car mus have an id to be updated");
3531
}
3632

@@ -43,13 +39,6 @@ public Car get(UUID uuid) {
4339
@CacheEvict(value = "cars")
4440
public void delete(UUID uuid) {
4541
carRepository.deleteById(uuid);
46-
System.out.println(cacheManager.getClass().getCanonicalName());
47-
// long cacheHits = ((HazelcastCacheManager) cacheManager).getHazelcastInstance().getMap("cars").getLocalMapStats().getHits();
48-
// System.out.println(((HazelcastCacheManager) cacheManager).getHazelcastInstance().getMap("cars").getLocalMapStats());
49-
// long cacheMisses = ((HazelcastCacheManager) cacheManager).getHazelcastInstance().getCacheManager().getCache("cars").getLocalCacheStatistics().getCacheMisses();
50-
//
51-
// System.out.println("hits:" + cacheHits);
52-
// System.out.println("misses:" + cacheMisses);
5342
}
5443

5544
}

0 commit comments

Comments
 (0)