Skip to content
Snippets Groups Projects
Commit 0b0eb194 authored by Daniel's avatar Daniel
Browse files

ENH: Option to disable caching added.

parent d3a20a4b
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,7 @@ BUGTRACKER_URI= ...@@ -49,6 +49,7 @@ BUGTRACKER_URI=
TRANSACTION_BENCHMARK_ENABLED=true TRANSACTION_BENCHMARK_ENABLED=true
CACHE_CONF_LOC=./conf/core/cache.ccf CACHE_CONF_LOC=./conf/core/cache.ccf
CACHE_DISABLE=false
INSERT_FILES_IN_DIR_ALLOWED_DIRS= INSERT_FILES_IN_DIR_ALLOWED_DIRS=
......
...@@ -91,6 +91,7 @@ public class ServerProperties extends Properties { ...@@ -91,6 +91,7 @@ public class ServerProperties extends Properties {
public static final String KEY_ACTIVATION_TIMEOUT_MS = "ACTIVATION_TIMEOUT_MS"; public static final String KEY_ACTIVATION_TIMEOUT_MS = "ACTIVATION_TIMEOUT_MS";
public static final String KEY_CACHE_CONF_LOC = "CACHE_CONF_LOC"; public static final String KEY_CACHE_CONF_LOC = "CACHE_CONF_LOC";
public static final String KEY_CACHE_DISABLE = "CACHE_DISABLE";
public static final String KEY_TRANSACTION_BENCHMARK_ENABLED = "TRANSACTION_BENCHMARK_ENABLED"; public static final String KEY_TRANSACTION_BENCHMARK_ENABLED = "TRANSACTION_BENCHMARK_ENABLED";
......
...@@ -62,25 +62,32 @@ public class JCSCacheHelper implements CacheHelper { ...@@ -62,25 +62,32 @@ public class JCSCacheHelper implements CacheHelper {
} }
public static void init() { public static void init() {
init(CaosDBServer.getServerProperty(ServerProperties.KEY_CACHE_CONF_LOC)); final boolean disabled =
Boolean.parseBoolean(CaosDBServer.getServerProperty(ServerProperties.KEY_CACHE_DISABLE));
init(CaosDBServer.getServerProperty(ServerProperties.KEY_CACHE_CONF_LOC), disabled);
} }
public static void init(String configFileLocation) { public static void init(String configFileLocation, boolean disabled) {
Properties config = null; Properties config = null;
try { if (disabled) {
Properties p = new Properties();
final InputStream is = new FileInputStream(configFileLocation);
p.load(is);
is.close();
config = p;
} catch (final FileNotFoundException e) {
logger.error(e);
config = getNOPCachingProperties();
} catch (final IOException e) {
logger.error(e);
config = getNOPCachingProperties(); config = getNOPCachingProperties();
logger.info("Configuring JCS Caching: disabled");
} else {
try {
Properties p = new Properties();
final InputStream is = new FileInputStream(configFileLocation);
p.load(is);
is.close();
config = p;
} catch (final FileNotFoundException e) {
logger.error(e);
config = getNOPCachingProperties();
} catch (final IOException e) {
logger.error(e);
config = getNOPCachingProperties();
}
logger.info("Configuring JCS Caching with {}", config);
} }
logger.info("Configuring JCS Caching with {}", config);
JCS.setConfigProperties(config); JCS.setConfigProperties(config);
} }
......
package caosdb.server.caching;
import static org.junit.Assert.assertEquals;
import caosdb.server.CaosDBServer;
import caosdb.server.ServerProperties;
import caosdb.server.database.backend.transaction.RetrieveProperties;
import java.io.IOException;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.CacheAccess;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestNoCaching {
@BeforeClass
public static void init() throws IOException {
CaosDBServer.initServerProperties();
CaosDBServer.setProperty(ServerProperties.KEY_CACHE_DISABLE, "TRUE");
JCSCacheHelper.init();
}
@Test
public void testCacheConfig() {
CacheAccess<String, String> retrieve_properties_cache =
JCS.getInstance(RetrieveProperties.CACHE_REGION);
assertEquals(0, retrieve_properties_cache.getCacheAttributes().getMaxObjects());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment