Updated cache clearing.
Change-Id: I3b660522dcb101f1998379d20190520eddff09cf
diff --git a/Changes b/Changes
index c7f6c8e..d7a8a06 100644
--- a/Changes
+++ b/Changes
@@ -1,7 +1,8 @@
-0.58 2018-07-25
+0.58.0 2018-07-26
- Implemented referencing cached collection (margaretha)
- Implemented deserialization of collection with array values and cache option (margaretha)
- Implemented caching collection (margaretha)
+ - Implemented KrillCollection cache clearing (margaretha)
0.57 2018-04-05
- [feature] Support text queries in metadata
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 8aa57c8..dfcea3a 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -73,7 +73,6 @@
import de.ids_mannheim.korap.response.Text;
import de.ids_mannheim.korap.util.KrillProperties;
import de.ids_mannheim.korap.util.QueryException;
-import net.sf.ehcache.CacheManager;
/**
* <p>KrillIndex implements a simple API for searching in and writing
@@ -373,6 +372,7 @@
this.writer().commit();
commitCounter = 0;
this.closeReader();
+ KrillCollection.cache.removeAll();
};
@@ -423,8 +423,6 @@
catch (IOException e) {
log.error("Unable to add document");
};
-
- CacheManager.getInstance().clearAll();
return doc;
};
@@ -454,8 +452,6 @@
catch (IOException e) {
log.error("Unable to delete documents");
};
-
- CacheManager.getInstance().clearAll();
return false;
};
@@ -504,7 +500,6 @@
fd.setUID(uid);
fd = this.addDoc(fd);
};
- CacheManager.getInstance().clearAll();
return fd;
};
@@ -561,7 +556,6 @@
return this.addDoc(fd);
};
- CacheManager.getInstance().clearAll();
return fd;
};
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java b/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
index 108c1e2..745a606 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
@@ -1,8 +1,8 @@
package de.ids_mannheim.korap.collection;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
@@ -15,7 +15,7 @@
import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KrillCollection;
import de.ids_mannheim.korap.KrillIndex;
-import net.sf.ehcache.CacheManager;
+import de.ids_mannheim.korap.index.FieldDocument;
import net.sf.ehcache.Element;
public class TestVCCaching {
@@ -33,10 +33,17 @@
}
@Test
- public void testCacheVC () throws IOException {
+ public void testCache () throws IOException {
+ testAddToCache();
+ testSearchCachedVC();
+ testClearCache();
+ }
+
+ private void testAddToCache () throws IOException {
InputStream is = getClass().getClassLoader()
.getResourceAsStream("named-vc/named-vc-free.jsonld");
String json = IOUtils.toString(is);
+ is.close();
KrillCollection kc = new KrillCollection(json);
kc.setIndex(index);
@@ -46,9 +53,6 @@
CachedVCData cc = (CachedVCData) element.getObjectValue();
assertTrue(cc.getDocIdMap().size() > 0);
-
- testSearchCachedVC();
- testClearCache();
}
private void testSearchCachedVC () throws IOException {
@@ -66,10 +70,35 @@
assertNotNull(result);
assertTrue(!result.isEmpty());
}
+
+ private void testClearCache () {
+ KrillCollection.cache.removeAll();
+
+ Element element = KrillCollection.cache.get("cache-goe");
+ assertNull(element);
+ }
+
+ @Test
+ public void testAddDocToIndex () throws IOException {
+ testAddToCache();
+
+ FieldDocument fd = new FieldDocument();
+ fd.addTV("base", "x y", "[(0-3)s:x]" + // 1
+ "[(3-4)s:y]" // 2
+ );
+ index.addDoc(fd);
+ index.commit();
+
+ Element element = KrillCollection.cache.get("cache-goe");
+ assertNull(element);
+ }
- public void testClearCache () {
- CacheManager cacheManager = CacheManager.getInstance();
- cacheManager.clearAll();
+ @Test
+ public void testDelDocFromIndex () throws IOException {
+ testAddToCache();
+
+ index.delDocs("textSigle", "GOE/AGF/00000");
+ index.commit();
Element element = KrillCollection.cache.get("cache-goe");
assertNull(element);