aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-08-18 11:13:14 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-08-18 11:13:14 +0200
commit6b0cc08317c9e2901af91542c0177182eaaf8c38 (patch)
tree6b36b1b6da8c6547ec0814a268a9a670285a5e3e /sonar-core
parent17aeea97bd1a04f84d6ed0b2f532d5597d300ca1 (diff)
downloadsonarqube-6b0cc08317c9e2901af91542c0177182eaaf8c38.tar.gz
sonarqube-6b0cc08317c9e2901af91542c0177182eaaf8c38.zip
SONAR-75 implement negative cache of rule descriptions
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java25
1 files changed, 14 insertions, 11 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java b/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java
index d1a98db5599..7ec38095fc9 100644
--- a/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java
+++ b/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java
@@ -45,7 +45,7 @@ public class I18nManager implements I18n, ServerExtension {
private Map<String, ClassLoader> bundleToClassloaders;
private Map<String, String> propertyToBundles;
private ClassLoader languagePackClassLoader;
- private Map<String,Map<Locale,String>> fileContentCache = Maps.newHashMap();
+ private Map<String, Map<Locale, String>> fileContentCache = Maps.newHashMap();
public I18nManager(PluginRepository pluginRepository) {
this.pluginRepository = pluginRepository;
@@ -108,11 +108,11 @@ public class I18nManager implements I18n, ServerExtension {
/**
* Only the given locale is searched. Contrary to java.util.ResourceBundle, no strategy for locating the bundle is implemented in
- * this method.
+ * this method.
*/
String messageFromFile(Locale locale, String filename, String relatedProperty, boolean keepInCache) {
- Map<Locale,String> fileCache = fileContentCache.get(filename);
- if (fileCache!=null && fileCache.containsKey(locale)) {
+ Map<Locale, String> fileCache = fileContentCache.get(filename);
+ if (fileCache != null && fileCache.containsKey(locale)) {
return fileCache.get(locale);
}
@@ -129,19 +129,22 @@ public class I18nManager implements I18n, ServerExtension {
if (input != null) {
try {
result = IOUtils.toString(input, "UTF-8");
- if (keepInCache && result!=null) {
- if (fileCache==null) {
- fileCache = Maps.newHashMap();
- fileContentCache.put(filename, fileCache);
- }
- fileCache.put(locale, result);
- }
+
} catch (IOException e) {
throw new SonarException("Fail to load file: " + filePath, e);
} finally {
IOUtils.closeQuietly(input);
}
}
+
+ if (keepInCache) {
+ if (fileCache == null) {
+ fileCache = Maps.newHashMap();
+ fileContentCache.put(filename, fileCache);
+ }
+ // put null value for negative caching.
+ fileCache.put(locale, result);
+ }
}
return result;
}