diff --git a/repository/src/main/java/org/alfresco/repo/cache/DefaultSimpleCache.java b/repository/src/main/java/org/alfresco/repo/cache/DefaultSimpleCache.java
index 422a902dc1..376330e12e 100644
--- a/repository/src/main/java/org/alfresco/repo/cache/DefaultSimpleCache.java
+++ b/repository/src/main/java/org/alfresco/repo/cache/DefaultSimpleCache.java
@@ -1,28 +1,28 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ * #L%
+ */
package org.alfresco.repo.cache;
import java.io.Serializable;
@@ -150,10 +150,24 @@ public final class DefaultSimpleCache
* @return true
if the put resulted in a change in value, false
otherwise.
*/
public boolean putAndCheckUpdate(K key, V value)
+ {
+ return putAndCheckUpdate(key, value, false);
+ }
+
+ /**
+ * put
method that may be used to check for updates in a thread-safe manner.
+ *
+ * @param includeNewCheck if true then we include the new value in the check
+ * @return true
if the put resulted in a change in value,
+ * or if includeNewCheck is true and the put resulted in a new value,
+ * false
otherwise.
+ */
+ public boolean putAndCheckUpdate(K key, V value, boolean includeNewCheck)
{
AbstractMap.SimpleImmutableEntry kvp = new AbstractMap.SimpleImmutableEntry(key, value);
AbstractMap.SimpleImmutableEntry priorKVP = cache.asMap().put(key, kvp);
- return priorKVP != null && (! priorKVP.equals(kvp));
+
+ return (includeNewCheck && priorKVP == null) || (priorKVP != null && (!priorKVP.equals(kvp)));
}
@Override
diff --git a/repository/src/main/resources/alfresco/tx-cache-context.xml b/repository/src/main/resources/alfresco/tx-cache-context.xml
index 8ab850ec58..6b47973f2c 100644
--- a/repository/src/main/resources/alfresco/tx-cache-context.xml
+++ b/repository/src/main/resources/alfresco/tx-cache-context.xml
@@ -136,6 +136,7 @@
+
diff --git a/repository/src/test/java/org/alfresco/repo/cache/DefaultSimpleCacheTest.java b/repository/src/test/java/org/alfresco/repo/cache/DefaultSimpleCacheTest.java
index ec0b5dec1e..43d97ed8f6 100644
--- a/repository/src/test/java/org/alfresco/repo/cache/DefaultSimpleCacheTest.java
+++ b/repository/src/test/java/org/alfresco/repo/cache/DefaultSimpleCacheTest.java
@@ -1,28 +1,28 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ * #L%
+ */
package org.alfresco.repo.cache;
import static org.junit.Assert.*;
@@ -131,6 +131,45 @@ public class DefaultSimpleCacheTest extends SimpleCacheTestBase