mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged 1.4 to HEAD
svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4380 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4386 . git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4659 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.alfresco.repo.cache;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.UserTransaction;
|
||||
@@ -86,6 +87,9 @@ public class CacheTest extends TestCase
|
||||
|
||||
assertEquals("AAA", backingCache.get("A"));
|
||||
|
||||
Collection<String> keys = backingCache.getKeys();
|
||||
assertEquals("Backing cache didn't return correct number of keys", 1, keys.size());
|
||||
|
||||
backingCache.remove("A");
|
||||
assertNull(backingCache.get("A"));
|
||||
}
|
||||
@@ -141,6 +145,11 @@ public class CacheTest extends TestCase
|
||||
assertEquals("Item not updated in txn cache", "XXX", transactionalCache.get(updatedTxnThree));
|
||||
assertFalse("Item was put into backing cache", backingCache.contains(updatedTxnThree));
|
||||
|
||||
// check that the keys collection is correct
|
||||
Collection<String> transactionalKeys = transactionalCache.getKeys();
|
||||
assertFalse("Transactionally removed item found in keys", transactionalKeys.contains(newGlobalOne));
|
||||
assertTrue("Transactionally added item not found in keys", transactionalKeys.contains(updatedTxnThree));
|
||||
|
||||
// commit the transaction
|
||||
txn.commit();
|
||||
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package org.alfresco.repo.cache;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheException;
|
||||
@@ -64,6 +65,12 @@ public class EhCacheAdapter<K extends Serializable, V extends Serializable>
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<K> getKeys()
|
||||
{
|
||||
return cache.getKeys();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public V get(K key)
|
||||
{
|
||||
|
72
source/java/org/alfresco/repo/cache/NullCache.java
vendored
Normal file
72
source/java/org/alfresco/repo/cache/NullCache.java
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.cache;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* A cache that does nothing - always.
|
||||
* <P/>
|
||||
* There are conditions under which code that expects to be caching, should not be. Using this
|
||||
* cache, it becomes possible to configure a valid cache in whilst still ensuring that the
|
||||
* actual caching is not performed.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class NullCache<K extends Serializable, V extends Serializable> implements SimpleCache<K, V>
|
||||
{
|
||||
public NullCache()
|
||||
{
|
||||
}
|
||||
|
||||
/** NO-OP */
|
||||
public boolean contains(K key)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection<K> getKeys()
|
||||
{
|
||||
return Collections.<K>emptyList();
|
||||
}
|
||||
|
||||
/** NO-OP */
|
||||
public V get(K key)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/** NO-OP */
|
||||
public void put(K key, V value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/** NO-OP */
|
||||
public void remove(K key)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/** NO-OP */
|
||||
public void clear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
@@ -17,6 +17,7 @@
|
||||
package org.alfresco.repo.cache;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Basic caching interface.
|
||||
@@ -32,6 +33,8 @@ public interface SimpleCache<K extends Serializable, V extends Serializable>
|
||||
{
|
||||
public boolean contains(K key);
|
||||
|
||||
public Collection<K> getKeys();
|
||||
|
||||
public V get(K key);
|
||||
|
||||
public void put(K key, V value);
|
||||
|
@@ -17,6 +17,8 @@
|
||||
package org.alfresco.repo.cache;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.ehcache.Cache;
|
||||
@@ -226,6 +228,39 @@ public class TransactionalCache<K extends Serializable, V extends Serializable>
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The keys returned are a union of the set of keys in the current transaction and
|
||||
* those in the backing cache.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<K> getKeys()
|
||||
{
|
||||
Collection<K> keys = null;
|
||||
// in-txn layering
|
||||
if (AlfrescoTransactionSupport.getTransactionId() != null)
|
||||
{
|
||||
keys = new HashSet<K>(23);
|
||||
TransactionData txnData = getTransactionData();
|
||||
if (!txnData.isClearOn)
|
||||
{
|
||||
// the backing cache is not due for a clear
|
||||
Collection<K> backingKeys = (Collection<K>) sharedCache.getKeys();
|
||||
keys.addAll(backingKeys);
|
||||
}
|
||||
// add keys
|
||||
keys.addAll((Collection<K>) txnData.updatedItemsCache.getKeys());
|
||||
// remove keys
|
||||
keys.removeAll((Collection<K>) txnData.removedItemsCache.getKeys());
|
||||
}
|
||||
else
|
||||
{
|
||||
// no transaction, so just use the backing cache
|
||||
keys = (Collection<K>) sharedCache.getKeys();
|
||||
}
|
||||
// done
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the per-transaction caches for the object before going to the shared cache.
|
||||
|
Reference in New Issue
Block a user