From ec7a10b7f8f2047687fed118351db07951096740 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Tue, 18 Aug 2009 08:58:53 +0000 Subject: [PATCH] Added cache clear method git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15778 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/cache/lookup/EntityLookupCache.java | 15 +++++++++++++++ .../repo/cache/lookup/EntityLookupCacheTest.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/source/java/org/alfresco/repo/cache/lookup/EntityLookupCache.java b/source/java/org/alfresco/repo/cache/lookup/EntityLookupCache.java index a935cb2675..bc02d1f67b 100644 --- a/source/java/org/alfresco/repo/cache/lookup/EntityLookupCache.java +++ b/source/java/org/alfresco/repo/cache/lookup/EntityLookupCache.java @@ -621,6 +621,21 @@ public class EntityLookupCache + * NOTE: This operation removes ALL entries for ALL cache regions. + */ + public void clear() + { + // Handle missing cache + if (cache == null) + { + return; + } + cache.clear(); + } + /** * Key-wrapper used to separate cache regions, allowing a single cache to be used for different * purposes. diff --git a/source/java/org/alfresco/repo/cache/lookup/EntityLookupCacheTest.java b/source/java/org/alfresco/repo/cache/lookup/EntityLookupCacheTest.java index 8cfe9f67fd..5a8c338a6b 100644 --- a/source/java/org/alfresco/repo/cache/lookup/EntityLookupCacheTest.java +++ b/source/java/org/alfresco/repo/cache/lookup/EntityLookupCacheTest.java @@ -213,6 +213,21 @@ public class EntityLookupCacheTest extends TestCase implements EntityLookupCallb assertNull(database.get(id)); assertEquals(0, cache.getKeys().size()); } + + public void testClear() throws Exception + { + TestValue valueOne = new TestValue(getName() + "-ONE"); + Pair entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne); + assertNotNull(entityPairOne); + Long id = entityPairOne.getFirst(); + assertEquals(valueOne.val, database.get(id)); + assertEquals(2, cache.getKeys().size()); + + // Clear it + entityLookupCacheA.clear(); + assertEquals(valueOne.val, database.get(id)); // Must still be in database + assertEquals(0, cache.getKeys().size()); // ... but cache must be empty + } /** * Helper class to represent business object