Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added generalt caching configuration and initial cache on the session…
… key server requests with a ttl of 5 minutes.
- Loading branch information
Andrew Dunn
committed
Mar 28, 2017
1 parent
24c73ea
commit fe162da
Showing
7 changed files
with
449 additions
and
11 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
rcloud-gist-service/src/main/java/com/mangosolutions/rcloud/rawgist/CacheConfiguration.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 AT&T Intellectual Property, [http://www.att.com] | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*******************************************************************************/ | ||
package com.mangosolutions.rcloud.rawgist; | ||
|
||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.util.StringUtils; | ||
|
||
import com.hazelcast.config.Config; | ||
import com.hazelcast.config.MapConfig; | ||
import com.hazelcast.core.HazelcastInstance; | ||
import com.hazelcast.spring.cache.HazelcastCacheManager; | ||
import com.mangosolutions.rcloud.rawgist.CacheConfigurationProperties.GistCacheConfiguration; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(CacheConfigurationProperties.class) | ||
public class CacheConfiguration { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(CacheConfiguration.class); | ||
|
||
@Autowired | ||
private CacheConfigurationProperties cacheConfigurationProperties; | ||
|
||
@Autowired | ||
private HazelcastInstance hazelcastInstance; | ||
|
||
@Bean | ||
public HazelcastCacheManager cacheManager() { | ||
HazelcastCacheManager cacheManager = new HazelcastCacheManager(hazelcastInstance); | ||
configureCaches(cacheManager); | ||
return cacheManager; | ||
} | ||
|
||
public void configureCaches(HazelcastCacheManager hazelcastCacheManager) { | ||
HazelcastInstance hazelcastInstance = hazelcastCacheManager.getHazelcastInstance(); | ||
for(GistCacheConfiguration cacheConfig: cacheConfigurationProperties.getCaches()) { | ||
String name = cacheConfig.getName(); | ||
if(!StringUtils.isEmpty(name)) { | ||
createAndApplyCacheConfiguration(hazelcastInstance, cacheConfig); | ||
} | ||
} | ||
} | ||
|
||
private void createAndApplyCacheConfiguration(HazelcastInstance hazelcastInstance, GistCacheConfiguration cacheConfig) { | ||
Config config = hazelcastInstance.getConfig(); | ||
Map<String, MapConfig> mapConfigs = config.getMapConfigs(); | ||
String cacheName = cacheConfig.getName(); | ||
if(mapConfigs.containsKey(cacheName)) { | ||
logger.warn("Altering existing configuration of cache config {}", mapConfigs.get(cacheName)); | ||
} | ||
MapConfig mapConfig = new MapConfig(cacheName);//config.getMapConfig(cacheConfig.getName()); | ||
mapConfig.setEvictionPercentage(cacheConfig.getEvictionPercentage()); | ||
mapConfig.setEvictionPolicy(cacheConfig.getEvictionPolicy()); | ||
mapConfig.setTimeToLiveSeconds(cacheConfig.getTtl()); | ||
mapConfig.setMinEvictionCheckMillis(cacheConfig.getEvictionCheck()); | ||
config.addMapConfig(mapConfig); | ||
logger.info("Configured cache {} with with settings: {}", cacheName, mapConfig); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...service/src/main/java/com/mangosolutions/rcloud/rawgist/CacheConfigurationProperties.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 AT&T Intellectual Property, [http://www.att.com] | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*******************************************************************************/ | ||
package com.mangosolutions.rcloud.rawgist; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
import com.hazelcast.config.EvictionPolicy; | ||
|
||
@ConfigurationProperties() | ||
public class CacheConfigurationProperties { | ||
|
||
private List<GistCacheConfiguration> caches; | ||
|
||
public List<GistCacheConfiguration> getCaches() { | ||
return caches; | ||
} | ||
|
||
public void setCaches(List<GistCacheConfiguration> caches) { | ||
this.caches = caches; | ||
} | ||
|
||
public static class GistCacheConfiguration { | ||
|
||
private String name; | ||
private int evictionPercentage = 25; | ||
private EvictionPolicy evictionPolicy = EvictionPolicy.LFU; | ||
private int ttl = 300; | ||
private int evictionCheck = 500; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
public int getEvictionPercentage() { | ||
return evictionPercentage; | ||
} | ||
public void setEvictionPercentage(int evictionPercentage) { | ||
this.evictionPercentage = evictionPercentage; | ||
} | ||
public EvictionPolicy getEvictionPolicy() { | ||
return evictionPolicy; | ||
} | ||
public void setEvictionPolicy(EvictionPolicy evictionPolicy) { | ||
this.evictionPolicy = evictionPolicy; | ||
} | ||
public int getTtl() { | ||
return ttl; | ||
} | ||
public void setTtl(int ttl) { | ||
this.ttl = ttl; | ||
} | ||
public int getEvictionCheck() { | ||
return evictionCheck; | ||
} | ||
public void setEvictionCheck(int evictionCheck) { | ||
this.evictionCheck = evictionCheck; | ||
} | ||
|
||
} | ||
|
||
|
||
} |
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
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
Oops, something went wrong.