You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by to...@apache.org on 2016/04/21 14:05:55 UTC
svn commit: r1740287 -
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
Author: tomekr
Date: Thu Apr 21 12:05:55 2016
New Revision: 1740287
URL: http://svn.apache.org/viewvc?rev=1740287&view=rev
Log:
OAK-4266: NodeDocumentCache#get method should be synchronized
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java?rev=1740287&r1=1740286&r2=1740287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java Thu Apr 21 12:05:55 2016
@@ -134,6 +134,10 @@ public class NodeDocumentCache implement
/**
* Return the document matching given key, optionally loading it from an
* external source.
+ * <p>
+ * This method can modify the cache, so it's synchronized. The {@link #getIfPresent(String)}
+ * is not synchronized and will be faster if you need to get the cached value
+ * outside the critical section.
*
* @see Cache#get(Object, Callable)
* @param key document key
@@ -143,10 +147,15 @@ public class NodeDocumentCache implement
@Nonnull
public NodeDocument get(@Nonnull String key, @Nonnull Callable<NodeDocument> valueLoader)
throws ExecutionException {
- if (isLeafPreviousDocId(key)) {
- return prevDocumentsCache.get(new StringValue(key), valueLoader);
- } else {
- return nodeDocumentsCache.get(new StringValue(key), valueLoader);
+ Lock lock = locks.acquire(key);
+ try {
+ if (isLeafPreviousDocId(key)) {
+ return prevDocumentsCache.get(new StringValue(key), valueLoader);
+ } else {
+ return nodeDocumentsCache.get(new StringValue(key), valueLoader);
+ }
+ } finally {
+ lock.unlock();
}
}