package io.reflectoring.cache.cleint.client;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import io.reflectoring.cache.cleint.rest.Car;
import org.springframework.stereotype.Component;

@Component
public class CacheClient {

    private static final String CARS = "cars";

    private HazelcastInstance client = HazelcastClient.newHazelcastClient();

    public Car put(String key, Car car){
        IMap<String, Car> map = client.getMap(CARS);
        return map.putIfAbsent(key, car);
    }

    public Car get(String key){
        IMap<String, Car> map = client.getMap(CARS);
        return map.get(key);
    }
}

@@ -84,16 +84,110 @@
 Client;%0A
+import com.hazelcast.client.config.ClientConfig;%0Aimport com.hazelcast.config.NearCacheConfig;%0A
 import c
@@ -511,16 +511,35 @@
 tClient(
+creatClientConfig()
 );%0A%0A    
@@ -573,16 +573,17 @@
 Car car)
+ 
 %7B%0A      
@@ -708,16 +708,17 @@
 ing key)
+ 
 %7B%0A      
@@ -798,11 +798,511 @@
 );%0A    %7D
+%0A%0A    private ClientConfig creatClientConfig() %7B%0A        ClientConfig clientConfig = new ClientConfig();%0A        clientConfig.addNearCacheConfig(createNearCacheConfig());%0A        return clientConfig;%0A    %7D%0A%0A    private NearCacheConfig createNearCacheConfig() %7B%0A        NearCacheConfig nearCacheConfig = new NearCacheConfig();%0A        nearCacheConfig.setName(CARS);%0A        nearCacheConfig.setTimeToLiveSeconds(360);%0A        nearCacheConfig.setMaxIdleSeconds(60);%0A        return nearCacheConfig;%0A    %7D
 %0A%7D%0A

use nearCache