-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow redis service unavailable when Redis is enabled
- Loading branch information
1 parent
0ed4759
commit 63d9ab0
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
...rsistence-api/src/main/java/org/cbioportal/persistence/util/LoggingCacheErrorHandler.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,43 @@ | ||
package org.cbioportal.persistence.util; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.cache.Cache; | ||
import org.springframework.cache.interceptor.CacheErrorHandler; | ||
|
||
/** | ||
* Implementation of org.springframework.cache.interceptor.CacheErrorHandler | ||
* that logs the error messages when performing Redis operations. | ||
* Redis will throw a RuntimeException causing our APIs to return HTTP 500 responses, so we defined | ||
* this class to just log the errors and allow our app fallback to the non-cached version. | ||
*/ | ||
|
||
public class LoggingCacheErrorHandler implements CacheErrorHandler { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(LoggingCacheErrorHandler.class); | ||
|
||
@Override | ||
public void handleCacheGetError(RuntimeException exception, Cache cache, Object key) { | ||
LOG.error(String.format("Cache '%s' failed to get entry with key '%s'", cache.getName(), key), exception); | ||
exception.printStackTrace(); | ||
} | ||
|
||
@Override | ||
public void handleCachePutError(RuntimeException exception, Cache cache, Object key, Object value) { | ||
LOG.error(String.format("Cache '%s' failed to put entry with key '%s'", cache.getName(), key), exception); | ||
exception.printStackTrace(); | ||
} | ||
|
||
@Override | ||
public void handleCacheEvictError(RuntimeException exception, Cache cache, Object key) { | ||
LOG.error(String.format("Cache '%s' failed to evict entry with key '%s'", cache.getName(), key), exception); | ||
exception.printStackTrace(); | ||
} | ||
|
||
@Override | ||
public void handleCacheClearError(RuntimeException exception, Cache cache) { | ||
LOG.error(String.format("Cache '%s' failed to clear entries", cache.getName()), exception); | ||
exception.printStackTrace(); | ||
} | ||
|
||
} |