-
-
Save Mistic92/8649515ff026e24ca0870ed61739a17c to your computer and use it in GitHub Desktop.
Apache ignite problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Slf4j | |
@Configuration | |
public class CacheConfig { | |
public static final int LRU_EVICTION_MAX = 10000; | |
public static final int MAX_AGE_MINUTES = 60 * 24; | |
@Profile("!dev") | |
@Bean | |
public CacheMode provideCacheMode() { | |
return CacheMode.PARTITIONED; | |
} | |
@Profile("dev") | |
@Bean | |
public CacheMode provideLocalCacheMode() { | |
return CacheMode.LOCAL; | |
} | |
@Bean | |
public CacheConfiguration provideTemplateCacheConfiguration(CacheMode cacheMode) { | |
CacheConfiguration config = new CacheConfiguration(); | |
Duration duration = new Duration(TimeUnit.MINUTES, MAX_AGE_MINUTES); | |
config.setCacheMode(cacheMode) | |
.setRebalanceMode(CacheRebalanceMode.ASYNC) | |
.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC) | |
.setCopyOnRead(false) | |
.setEvictionPolicy(new LruEvictionPolicy(LRU_EVICTION_MAX)) | |
.setOnheapCacheEnabled(true) | |
.setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(duration)) | |
.setManagementEnabled(true) | |
.setRebalanceTimeout(1000 * 15) | |
.setAtomicityMode(CacheAtomicityMode.ATOMIC) | |
; | |
return config; | |
} | |
@Bean | |
@Profile("!dev") | |
public IgniteConfiguration provideIgniteConfiguration(List<CacheConfiguration> cacheConfigs) | |
throws IgniteCheckedException { | |
IgniteConfiguration cfg = new IgniteConfiguration(); | |
cfg.setGridLogger(new Slf4jLogger()) | |
.setIgniteInstanceName("ignite") | |
.setClientMode(true) | |
.setMetricsLogFrequency(1000 * 60 * 10) | |
; | |
TcpDiscoverySpi discovery = new TcpDiscoverySpi(); | |
discovery.setIpFinder(new TcpDiscoveryKubernetesIpFinder()); | |
cfg.setDiscoverySpi(discovery); | |
return cfg; | |
} | |
@Profile("dev") | |
@Bean | |
public IgniteConfiguration provideDevIgniteConfiguration(List<CacheConfiguration> cacheConfigs) | |
throws IgniteCheckedException { | |
IgniteConfiguration cfg = new IgniteConfiguration(); | |
cfg.setGridLogger(new Slf4jLogger()) | |
.setIgniteInstanceName("ignite"); | |
return cfg; | |
} | |
@Bean("cacheManager") | |
public SpringCacheManager provideSpringCacheManager(IgniteConfiguration igniteConfiguration, | |
CacheConfiguration template) { | |
SpringCacheManager manager = new SpringCacheManager(); | |
manager.setIgniteInstanceName("ignite"); | |
manager.setConfiguration(igniteConfiguration); | |
manager.setDynamicCacheConfiguration(template); | |
return manager; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@CacheConfig(cacheNames = {"example-user"}) | |
public class ExampleRepo{ | |
@Cacheable(cacheNames = "example-user", key = "#userid,#val") | |
public Optional<ExampleUser> getUserById(String userid, int val) { | |
return Optional.ofNullable(manager.load(ExampleUser.class, userid)); | |
} | |
@Caching(evict = { | |
@CacheEvict(value = "example-user", key = "{#userId,0}") | |
}) | |
public void evictByUserID(String userId){ | |
System.out.println("evicted"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment