RedisCacheUtil { public static int getExpiryInSeconds(final String region) { try { String key = EXPIRY_PROPERTY_PREFIX + "." + region; String value = getProperty(key, String.valueOf(defaultExpiryInSeconds)); log.trace("load expiry property. region={}, expiryInSeconds={}", key, value); return Integer.parseInt(value); } catch (Exception e) { log.warn("Fail to get expiryInSeconds in region={}", region, e); return defaultExpiryInSeconds; } } private  RedisCacheUtil(); static int getDefaultExpiryInSeconds(); static Properties loadCacheProperties(final Properties props); static InputStream getFileInputStream(String path); static String getRedissonConfigPath(); static int getExpiryInSeconds(final String region); static String getProperty(final String key, String defaultValue); static Config getRedissonJavaConfig(); static void saveRedisSingletonClient(RedisClient client); static RedisClient getRedisSingletonClient(); static final String FILE_URL_PREFIX; static final String RESOURCE_URL_PREFIX; static final String EXPIRY_PROPERTY_PREFIX; static final int DEFAULT_EXPIRY_IN_SECONDS; static final String REDISSON_CONFIG; static final String REDISSON_JAVA_CONFIG; static final String DEFAULT_REDISSON_CONFIG_PATH; static final String REDIS_SINGLETON_CLIENT; }
@Test public void testGetExpiryInSeconds() throws Exception { Properties props = new Properties(); props.setProperty("hibernate.cache.provider_configuration_file_resource_path", "classpath:conf/hibernate-redis.properties"); RedisCacheUtil.loadCacheProperties(props); int expire = RedisCacheUtil.getExpiryInSeconds("xx"); log.debug("no defined region's expiry in seconds={}", expire); assertThat(expire).isEqualTo(RedisCacheUtil.getDefaultExpiryInSeconds()); assertThat(RedisCacheUtil.getExpiryInSeconds("default")).isEqualTo(360); assertThat(RedisCacheUtil.getExpiryInSeconds("hibernate.common")).isEqualTo(0); assertThat(RedisCacheUtil.getExpiryInSeconds("hibernate.account")).isEqualTo(1200); }