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/08/08 10:35:58 UTC
svn commit: r1755493 -
/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
Author: tomekr
Date: Mon Aug 8 10:35:58 2016
New Revision: 1755493
URL: http://svn.apache.org/viewvc?rev=1755493&view=rev
Log:
OAK-4123 Persistent cache: allow to configure the add data concurrency
Modified:
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java?rev=1755493&r1=1755492&r2=1755493&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java Mon Aug 8 10:35:58 2016
@@ -47,6 +47,12 @@ class NodeCache<K, V> implements Cache<K
private static final Set<RemovalCause> EVICTION_CAUSES = ImmutableSet.of(COLLECTED, EXPIRED, SIZE);
+ /**
+ * Whether to use the queue to put items into cache. Default: false (cache
+ * will be updated synchronously).
+ */
+ private static final boolean ASYNC_CACHE = Boolean.getBoolean("oak.cache.asynchronous");
+
private final PersistentCache cache;
private final Cache<K, V> memCache;
private final MultiGenerationMap<K, V> map;
@@ -69,7 +75,12 @@ class NodeCache<K, V> implements Cache<K
this.docStore = docStore;
PersistentCache.LOG.info("wrapping map " + this.type);
map = new MultiGenerationMap<K, V>();
- this.writerQueue = new CacheWriteQueue<K, V>(dispatcher, cache, map);
+
+ if (ASYNC_CACHE) {
+ this.writerQueue = new CacheWriteQueue<K, V>(dispatcher, cache, map);
+ } else {
+ this.writerQueue = null;
+ }
}
@Override
@@ -92,7 +103,7 @@ class NodeCache<K, V> implements Cache<K
}
private V readIfPresent(K key) {
- if (writerQueue.waitsForInvalidation(key)) {
+ if (ASYNC_CACHE && writerQueue.waitsForInvalidation(key)) {
return null;
}
cache.switchGenerationIfNeeded();
@@ -100,6 +111,15 @@ class NodeCache<K, V> implements Cache<K
return v;
}
+ private void write(final K key, final V value) {
+ cache.switchGenerationIfNeeded();
+ if (value == null) {
+ map.remove(key);
+ } else {
+ map.put(key, value);
+ }
+ }
+
@SuppressWarnings("unchecked")
@Override
@Nullable
@@ -124,6 +144,9 @@ class NodeCache<K, V> implements Cache<K
return value;
}
value = memCache.get(key, valueLoader);
+ if (!ASYNC_CACHE) {
+ write(key, value);
+ }
return value;
}
@@ -136,13 +159,20 @@ class NodeCache<K, V> implements Cache<K
@Override
public void put(K key, V value) {
memCache.put(key, value);
+ if (!ASYNC_CACHE) {
+ write(key, value);
+ }
}
@SuppressWarnings("unchecked")
@Override
public void invalidate(Object key) {
memCache.invalidate(key);
- writerQueue.addInvalidate(singleton((K) key));
+ if (ASYNC_CACHE) {
+ writerQueue.addInvalidate(singleton((K) key));
+ } else {
+ write((K) key, null);
+ }
}
@Override
@@ -186,7 +216,7 @@ class NodeCache<K, V> implements Cache<K
*/
@Override
public void evicted(K key, V value, RemovalCause cause) {
- if (EVICTION_CAUSES.contains(cause) && value != null) {
+ if (ASYNC_CACHE && EVICTION_CAUSES.contains(cause) && value != null) {
// invalidations are handled separately
writerQueue.addPut(key, value);
}