Commit 542b30a2 authored by Bill Wang's avatar Bill Wang
Browse files

update cache impl

parent 4aeb8998
......@@ -14,6 +14,10 @@
package org.opengroup.osdu.search.provider.aws.cache;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.opengroup.osdu.core.aws.cache.AwsElasticCache;
import org.opengroup.osdu.core.aws.ssm.K8sParameterNotFoundException;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.search.cache.CursorCache;
import org.opengroup.osdu.core.common.model.search.CursorSettings;
......@@ -23,21 +27,25 @@ import org.springframework.stereotype.Component;
@Component
public class CursorCacheImpl implements CursorCache {
private RedisCache<String, CursorSettings> cache;
private ICache<String, CursorSettings> cache;
private Boolean local;
public void close() throws Exception {
if (this.local){
// local dummy cache, no need to close
}else{
((RedisCache)this.cache).close();
}
}
/**
* Initializes a Cursor Cache with Redis connection parameters specified in the application
* properties file.
* @param REDIS_SEARCH_HOST - the hostname of the Cursor Cache Redis cluster.
* @param REDIS_SEARCH_PORT - the port of the Cursor Cache Redis cluster.
*
* @param INDEX_CACHE_EXPIRATION - the expiration time for the Cursor Cache Redis cluster.
*/
public CursorCacheImpl(@Value("${aws.elasticache.cluster.cursor.endpoint}") final String REDIS_SEARCH_HOST,
@Value("${aws.elasticache.cluster.cursor.port}") final String REDIS_SEARCH_PORT,
@Value("${aws.elasticache.cluster.cursor.key}") final String REDIS_SEARCH_KEY,
@Value("${aws.elasticache.cluster.cursor.expiration}") final String INDEX_CACHE_EXPIRATION) {
cache = new RedisCache<String, CursorSettings>(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), REDIS_SEARCH_KEY,
Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60, String.class, CursorSettings.class);
public CursorCacheImpl(@Value("${aws.elasticache.cluster.cursor.expiration}") final String INDEX_CACHE_EXPIRATION) throws K8sParameterNotFoundException, JsonProcessingException {
cache = AwsElasticCache.RedisCache(Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60, String.class, CursorSettings.class);
local = cache.getClass() != RedisCache.class;
}
/**
......
......@@ -14,8 +14,11 @@
package org.opengroup.osdu.search.provider.aws.cache;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.opengroup.osdu.core.aws.cache.AwsElasticCache;
import org.opengroup.osdu.core.aws.ssm.K8sParameterNotFoundException;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.core.common.model.search.CursorSettings;
import org.opengroup.osdu.search.cache.IFieldTypeMappingCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -25,21 +28,16 @@ import java.util.Map;
@Component
public class FieldTypeMappingCacheImpl implements IFieldTypeMappingCache {
private RedisCache<String, Map> cache;
private ICache<String,Map> cache;
private Boolean local;
/**
* Initializes a Cursor Cache with Redis connection parameters specified in the application
* properties file.
*
* @param REDIS_SEARCH_HOST - the hostname of the Cursor Cache Redis cluster.
* @param REDIS_SEARCH_PORT - the port of the Cursor Cache Redis cluster.
*/
public FieldTypeMappingCacheImpl(@Value("${aws.elasticache.cluster.cursor.endpoint}") final String REDIS_SEARCH_HOST,
@Value("${aws.elasticache.cluster.cursor.port}") final String REDIS_SEARCH_PORT,
@Value("${aws.elasticache.cluster.cursor.key}") final String REDIS_SEARCH_KEY,
@Value("${aws.elasticache.cluster.cursor.expiration}") final String INDEX_CACHE_EXPIRATION) {
cache = new RedisCache<String, Map>(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), REDIS_SEARCH_KEY,
Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60, String.class, Map.class);
public FieldTypeMappingCacheImpl(@Value("${aws.elasticache.cluster.cursor.expiration}") final String INDEX_CACHE_EXPIRATION) throws K8sParameterNotFoundException, JsonProcessingException {
cache = AwsElasticCache.RedisCache(Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60, String.class, Map.class);
local = cache.getClass() != RedisCache.class;
}
/**
......
......@@ -40,7 +40,6 @@ public class IndexCacheImpl implements IIndexCache<String, Boolean>, AutoCloseab
}else{
((RedisCache)this.cache).close();
}
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment