Skip to content

Commit

Permalink
Disabled message caching in CmsMultiMessages for VFS-based message
Browse files Browse the repository at this point in the history
bundles since they are mutable.
  • Loading branch information
gWestenberger committed Sep 16, 2013
1 parent d9a3a36 commit 52a6e86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/org/opencms/i18n/CmsMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ public boolean isInitialized() {
return (m_resourceBundle != null);
}

/**
* Indicates that users of this CmsMessages instance should not cache message from it.<p>
*
* @return true if messages from this CmsMessages instance should not be cached
*/
public boolean isUncacheable() {

return (m_resourceBundle instanceof CmsVfsResourceBundle);
}

/**
* Returns the localized resource string for a given message key.<p>
*
Expand Down
8 changes: 6 additions & 2 deletions src/org/opencms/i18n/CmsMultiMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,14 @@ private String resolveKey(String keyName) {
// key was already checked and not found
return null;
}
boolean noCache = false;
if (result == null) {
// so far not in the cache
for (int i = 0; (result == null) && (i < m_messages.size()); i++) {
try {
result = (m_messages.get(i)).getString(keyName);
// if no exception is thrown here we have found the result
noCache |= m_messages.get(i).isUncacheable();
} catch (CmsMessageException e) {
// can usually be ignored
if (LOG.isDebugEnabled()) {
Expand All @@ -243,8 +245,10 @@ private String resolveKey(String keyName) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_MESSAGE_KEY_FOUND_2, keyName, result));
}
// cache the result
m_messageCache.put(keyName, result);
if (!noCache) {
// cache the result
m_messageCache.put(keyName, result);
}
}
// return the result
return result;
Expand Down

0 comments on commit 52a6e86

Please sign in to comment.