mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Fix cache in NodeTypeUtility to be thread safe.
Inspired by @cetra3 in PR: https://github.com/Alfresco/records-management/pull/8
This commit is contained in:
@@ -26,8 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.module.org_alfresco_module_rm.util;
|
package org.alfresco.module.org_alfresco_module_rm.util;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.WeakHashMap;
|
|
||||||
|
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
@@ -41,11 +40,12 @@ import org.alfresco.util.ParameterCheck;
|
|||||||
*/
|
*/
|
||||||
public class NodeTypeUtility
|
public class NodeTypeUtility
|
||||||
{
|
{
|
||||||
|
/** Static cache for results of types that are instances of other Alfresco types. */
|
||||||
|
private static ConcurrentHashMap<String, Boolean> instanceOfCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/** Dictionary service */
|
/** Dictionary service */
|
||||||
private DictionaryService dictionaryService;
|
private DictionaryService dictionaryService;
|
||||||
|
|
||||||
private static Map<String, Boolean> instanceOfCache = new WeakHashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param dictionaryService dictionary service
|
* @param dictionaryService dictionary service
|
||||||
*/
|
*/
|
||||||
@@ -66,24 +66,8 @@ public class NodeTypeUtility
|
|||||||
ParameterCheck.mandatory("className", className);
|
ParameterCheck.mandatory("className", className);
|
||||||
ParameterCheck.mandatory("ofClassName", ofClassName);
|
ParameterCheck.mandatory("ofClassName", ofClassName);
|
||||||
|
|
||||||
boolean result = false;
|
|
||||||
|
|
||||||
String key = className.toString() + "|" + ofClassName.toString();
|
String key = className.toString() + "|" + ofClassName.toString();
|
||||||
if (instanceOfCache.containsKey(key))
|
return instanceOfCache.computeIfAbsent(key, k ->
|
||||||
{
|
(ofClassName.equals(className) || dictionaryService.isSubClass(className, ofClassName)));
|
||||||
result = instanceOfCache.get(key);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ofClassName.equals(className) ||
|
|
||||||
dictionaryService.isSubClass(className, ofClassName))
|
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceOfCache.put(key, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user