You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2014/03/05 13:24:17 UTC

[02/21] started working on cleaner cache API for KiWi

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
new file mode 100644
index 0000000..167b0c9
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.apache.marmotta.kiwi.caching;
+
+import org.apache.marmotta.kiwi.model.rdf.*;
+
+import java.util.Map;
+
+/**
+ * A generic cache manager API implemented by different caching backends. Each cache should be made accessible
+ * using the Java Map interface.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public interface CacheManager {
+
+
+    /**
+     * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
+     * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
+     *
+     * @return an EHCache Cache instance containing the node id -> node mappings
+     */
+    public Map<Long, KiWiNode> getNodeCache();
+
+
+    /**
+     * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
+     * construction of query results.
+     *
+     * @return
+     */
+    public Map<Long, KiWiTriple> getTripleCache();
+
+
+    /**
+     * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
+     * KiWiUriResources to avoid a database lookup.
+     *
+     * @return
+     */
+    public Map<String, KiWiUriResource> getUriCache();
+
+
+    /**
+     * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
+     * KiWiAnonResources to avoid a database lookup.
+     *
+     * @return
+     */
+    public Map<String, KiWiAnonResource> getBNodeCache();
+
+
+
+    /**
+     * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
+     * KiWiLiterals to avoid a database lookup.
+     *
+     * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+     * @return
+     */
+    public Map<String, KiWiLiteral> getLiteralCache();
+
+
+    /**
+     * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+     * @return
+     */
+    public Map<String, KiWiNamespace> getNamespaceUriCache();
+
+
+    /**
+     * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+     * @return
+     */
+    public Map<String, KiWiNamespace> getNamespacePrefixCache();
+
+
+    /**
+     * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
+     * cache and should be used with care.
+     * @return
+     */
+    public Map<Long,Long> getRegistryCache();
+
+
+
+    /**
+     * Get the cache with the given name from the cache manager. Can be used to request additional
+     * caches from the cache manager that are not covered by explicit methods.
+     *
+     * @param name
+     * @return
+     */
+    public Map getCacheByName(String name);
+
+
+    /**
+     * Clear all caches managed by this cache manager.
+     */
+    public void clear();
+
+    /**
+     * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+     */
+    public void shutdown();
+
+
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerFactory.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerFactory.java
new file mode 100644
index 0000000..3a33e05
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerFactory.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.apache.marmotta.kiwi.caching;
+
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Factory classes for creating cache manager instances.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public interface CacheManagerFactory {
+
+    /**
+     * Create a new cache manager instance using the KiWiConfiguration passed as argument.
+     *
+     * @param configuration KiWi configuration used by the underlying triple store
+     * @return a new cache manager instance for this triple store
+     */
+    public CacheManager createCacheManager(KiWiConfiguration configuration);
+
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
deleted file mode 100644
index ba0db2b..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class DateLiteralExternalizer implements AdvancedExternalizer<KiWiDateLiteral> {
-
-    @Override
-    public Set<Class<? extends KiWiDateLiteral>> getTypeClasses() {
-        return Util.<Class<? extends KiWiDateLiteral>>asSet(KiWiDateLiteral.class);
-    }
-
-    @Override
-    public Integer getId() {
-        return ExternalizerIds.DATE_LITERAL;
-    }
-
-    @Override
-    public void writeObject(ObjectOutput output, KiWiDateLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeLong(object.getDateContent().getTime());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
-    }
-
-    @Override
-    public KiWiDateLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        Date content = new Date(input.readLong());
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
-    }
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
deleted file mode 100644
index 710a8a3..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class DoubleLiteralExternalizer implements AdvancedExternalizer<KiWiDoubleLiteral> {
-
-    @Override
-    public Set<Class<? extends KiWiDoubleLiteral>> getTypeClasses() {
-        return Util.<Class<? extends KiWiDoubleLiteral>>asSet(KiWiDoubleLiteral.class);
-    }
-
-    @Override
-    public Integer getId() {
-        return ExternalizerIds.DOUBLE_LITERAL;
-    }
-
-    @Override
-    public void writeObject(ObjectOutput output, KiWiDoubleLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeDouble(object.getDoubleContent());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
-    }
-
-    @Override
-    public KiWiDoubleLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        double content = input.readDouble();
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
-    }
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java
deleted file mode 100644
index da1eb64..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.apache.marmotta.kiwi.caching;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class ExternalizerIds {
-
-    public static final int URI = 17;
-
-    public static final int BNODE = 23;
-
-    public static final int STRING_LITERAL = 19;
-
-    public static final int INT_LITERAL = 39;
-
-    public static final int DOUBLE_LITERAL = 37;
-
-    public static final int DATE_LITERAL = 29;
-
-    public static final int BOOL_LITERAL = 31;
-
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManager.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManager.java
new file mode 100644
index 0000000..d60221c
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManager.java
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.apache.marmotta.kiwi.caching;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A simple implementation of a cache manager using the Guava caching functionality. Does not support clustered
+ * operation.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class GuavaCacheManager implements CacheManager {
+
+    private static Logger log = LoggerFactory.getLogger(GuavaCacheManager.class);
+
+    private KiWiConfiguration configuration;
+
+    private Cache<Long,KiWiNode> nodeCache;
+    private Cache<Long,KiWiTriple> tripleCache;
+    private Cache<String,KiWiUriResource> uriCache;
+    private Cache<String,KiWiAnonResource> bnodeCache;
+    private Cache<String,KiWiLiteral> literalCache;
+    private Cache<String,KiWiNamespace> namespaceUriCache, namespacePrefixCache;
+    private ConcurrentHashMap<Long,Long> registryCache;
+
+    private Map<String,Cache> dynamicCaches;
+
+
+    public GuavaCacheManager(KiWiConfiguration configuration) {
+        this.configuration = configuration;
+
+        log.info("initialising Guava in-memory caching backend ...");
+
+        if(configuration.isClustered()) {
+            log.warn("clustering not supported by Guava in-memory caching backend; please use Infinispan or Hazelcast instead!");
+        }
+
+        nodeCache = CacheBuilder.newBuilder()
+                .maximumSize(configuration.getNodeCacheSize())
+                .expireAfterAccess(30, TimeUnit.MINUTES)
+                .build();
+
+        tripleCache = CacheBuilder.newBuilder()
+                .maximumSize(configuration.getTripleCacheSize())
+                .expireAfterAccess(30, TimeUnit.MINUTES)
+                .build();
+
+        uriCache = CacheBuilder.newBuilder()
+                .maximumSize(configuration.getUriCacheSize())
+                .expireAfterAccess(30, TimeUnit.MINUTES)
+                .build();
+
+        bnodeCache = CacheBuilder.newBuilder()
+                .maximumSize(configuration.getBNodeCacheSize())
+                .expireAfterAccess(30, TimeUnit.MINUTES)
+                .build();
+
+        literalCache = CacheBuilder.newBuilder()
+                .maximumSize(configuration.getLiteralCacheSize())
+                .expireAfterAccess(30, TimeUnit.MINUTES)
+                .build();
+
+        namespaceUriCache = CacheBuilder.newBuilder()
+                .maximumSize(configuration.getNamespaceCacheSize())
+                .expireAfterAccess(1, TimeUnit.DAYS)
+                .build();
+
+        namespacePrefixCache = CacheBuilder.newBuilder()
+                .maximumSize(configuration.getNamespaceCacheSize())
+                .expireAfterAccess(1, TimeUnit.DAYS)
+                .build();
+
+
+        registryCache = new ConcurrentHashMap<>();
+
+        dynamicCaches = new HashMap<>();
+
+    }
+
+    /**
+     * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
+     * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
+     *
+     * @return an EHCache Cache instance containing the node id -> node mappings
+     */
+    @Override
+    public Map<Long, KiWiNode> getNodeCache() {
+        return nodeCache.asMap();
+    }
+
+    /**
+     * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
+     * construction of query results.
+     *
+     * @return
+     */
+    @Override
+    public Map<Long, KiWiTriple> getTripleCache() {
+        return tripleCache.asMap();
+    }
+
+    /**
+     * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
+     * KiWiUriResources to avoid a database lookup.
+     *
+     * @return
+     */
+    @Override
+    public Map<String, KiWiUriResource> getUriCache() {
+        return uriCache.asMap();
+    }
+
+    /**
+     * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
+     * KiWiAnonResources to avoid a database lookup.
+     *
+     * @return
+     */
+    @Override
+    public Map<String, KiWiAnonResource> getBNodeCache() {
+        return bnodeCache.asMap();
+    }
+
+    /**
+     * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
+     * KiWiLiterals to avoid a database lookup.
+     *
+     * @return
+     * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+     */
+    @Override
+    public Map<String, KiWiLiteral> getLiteralCache() {
+        return literalCache.asMap();
+    }
+
+    /**
+     * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+     *
+     * @return
+     */
+    @Override
+    public Map<String, KiWiNamespace> getNamespaceUriCache() {
+        return namespaceUriCache.asMap();
+    }
+
+    /**
+     * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+     *
+     * @return
+     */
+    @Override
+    public Map<String, KiWiNamespace> getNamespacePrefixCache() {
+        return namespacePrefixCache.asMap();
+    }
+
+    /**
+     * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
+     * cache and should be used with care.
+     *
+     * @return
+     */
+    @Override
+    public Map<Long, Long> getRegistryCache() {
+        return registryCache;
+    }
+
+    /**
+     * Get the cache with the given name from the cache manager. Can be used to request additional
+     * caches from the cache manager that are not covered by explicit methods.
+     *
+     * @param name
+     * @return
+     */
+    @Override
+    public Map getCacheByName(String name) {
+        synchronized (dynamicCaches) {
+            if(!dynamicCaches.containsKey(name)) {
+                dynamicCaches.put(name, CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.MINUTES).maximumSize(100000).build());
+            }
+            return dynamicCaches.get(name).asMap();
+        }
+    }
+
+    /**
+     * Clear all caches managed by this cache manager.
+     */
+    @Override
+    public void clear() {
+        for(Cache c : dynamicCaches.values()) {
+            c.invalidateAll();
+        }
+
+        for(Cache c : new Cache[] { nodeCache, uriCache, bnodeCache, literalCache, tripleCache, namespacePrefixCache, namespaceUriCache}) {
+            c.invalidateAll();
+        }
+
+        registryCache.clear();
+    }
+
+    /**
+     * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+     */
+    @Override
+    public void shutdown() {
+        dynamicCaches.clear();
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManagerFactory.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManagerFactory.java
new file mode 100644
index 0000000..70dfc86
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManagerFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.apache.marmotta.kiwi.caching;
+
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Create simple Guava-based in-memory caches.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class GuavaCacheManagerFactory implements CacheManagerFactory {
+
+    public GuavaCacheManagerFactory() {
+    }
+
+    /**
+     * Create a new cache manager instance using the KiWiConfiguration passed as argument.
+     *
+     * @param configuration KiWi configuration used by the underlying triple store
+     * @return a new cache manager instance for this triple store
+     */
+    @Override
+    public CacheManager createCacheManager(KiWiConfiguration configuration) {
+        return new GuavaCacheManager(configuration);
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
deleted file mode 100644
index 8001f87..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class IntLiteralExternalizer implements AdvancedExternalizer<KiWiIntLiteral> {
-
-    @Override
-    public Set<Class<? extends KiWiIntLiteral>> getTypeClasses() {
-        return Util.<Class<? extends KiWiIntLiteral>>asSet(KiWiIntLiteral.class);
-    }
-
-    @Override
-    public Integer getId() {
-        return ExternalizerIds.INT_LITERAL;
-    }
-
-    @Override
-    public void writeObject(ObjectOutput output, KiWiIntLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeLong(object.getIntContent());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
-    }
-
-    @Override
-    public KiWiIntLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        long content = input.readLong();
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
-    }
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
deleted file mode 100644
index 9760a66..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
+++ /dev/null
@@ -1,528 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.apache.marmotta.kiwi.caching;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.infinispan.Cache;
-import org.infinispan.commons.CacheException;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.configuration.cache.CacheMode;
-import org.infinispan.configuration.cache.Configuration;
-import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.configuration.global.GlobalConfiguration;
-import org.infinispan.configuration.global.GlobalConfigurationBuilder;
-import org.infinispan.context.Flag;
-import org.infinispan.distribution.ch.SyncConsistentHashFactory;
-import org.infinispan.eviction.EvictionStrategy;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.marmotta.kiwi.config.CacheMode.DISTRIBUTED;
-import static org.apache.marmotta.kiwi.config.CacheMode.REPLICATED;
-
-/**
- * A class for managing the different caches that are used by the triple store.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class KiWiCacheManager {
-
-    private static Logger log = LoggerFactory.getLogger(KiWiCacheManager.class);
-
-    public static final String NODE_CACHE = "node-cache";
-    public static final String TRIPLE_CACHE = "triple-cache";
-    public static final String URI_CACHE = "uri-cache";
-    public static final String BNODE_CACHE = "bnode-cache";
-    public static final String LITERAL_CACHE = "literal-cache";
-    public static final String NAMESPACE_URI_CACHE = "namespace-uri-cache";
-    public static final String NAMESPACE_PREFIX_CACHE = "namespace-prefix-cache";
-    public static final String LOADER_CACHE = "loader-cache";
-    public static final String REGISTRY_CACHE = "registry-cache";
-
-    private EmbeddedCacheManager cacheManager;
-
-    private GlobalConfiguration globalConfiguration;
-
-    // default configuration: distributed cache, 100000 entries, 300 seconds expiration, 60 seconds idle
-    private Configuration defaultConfiguration;
-
-    private boolean clustered, embedded;
-
-    private KiWiConfiguration kiWiConfiguration;
-
-
-    private Cache nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, loaderCache, registryCache;
-
-
-    /**
-     * Create a new cache manager with its own automatically created Infinispan instance.
-     *
-     * @param config
-     */
-    public KiWiCacheManager(KiWiConfiguration config, AdvancedExternalizer...externalizers) {
-
-        this.clustered = config.isClustered();
-        this.kiWiConfiguration = config;
-
-        if(clustered && (config.getCacheMode() == DISTRIBUTED || config.getCacheMode() == REPLICATED)) {
-            try {
-                String jgroupsXml = IOUtils.toString(KiWiCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
-
-                jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
-                jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
-
-
-                globalConfiguration = new GlobalConfigurationBuilder()
-                        .classLoader(KiWiCacheManager.class.getClassLoader())
-                        .transport()
-                            .defaultTransport()
-                            .clusterName(config.getClusterName())
-                            .machineId("instance-" + config.getDatacenterId())
-                            .addProperty("configurationXml", jgroupsXml)
-                        .globalJmxStatistics()
-                            .jmxDomain("org.apache.marmotta.kiwi")
-                            .allowDuplicateDomains(true)
-                        .serialization()
-                            .addAdvancedExternalizer(externalizers)
-                        .build();
-            } catch (IOException ex) {
-                log.warn("error loading JGroups configuration from archive: {}", ex.getMessage());
-                log.warn("some configuration options will not be available");
-
-                globalConfiguration = new GlobalConfigurationBuilder()
-                        .classLoader(KiWiCacheManager.class.getClassLoader())
-                            .transport()
-                            .defaultTransport()
-                            .clusterName(config.getClusterName())
-                            .machineId("instance-" + config.getDatacenterId())
-                            .addProperty("configurationFile", "jgroups-kiwi.xml")
-                        .globalJmxStatistics()
-                            .jmxDomain("org.apache.marmotta.kiwi")
-                            .allowDuplicateDomains(true)
-                        .serialization()
-                            .addAdvancedExternalizer(externalizers)
-                        .build();
-
-            }
-
-            if(config.getCacheMode() == DISTRIBUTED) {
-                defaultConfiguration = new ConfigurationBuilder()
-                        .clustering()
-                            .cacheMode(CacheMode.DIST_ASYNC)
-                            .async()
-                                .asyncMarshalling()
-                            .l1()
-                                .lifespan(5, TimeUnit.MINUTES)
-                            .hash()
-                                .numOwners(2)
-                                .numSegments(40)
-                                .consistentHashFactory(new SyncConsistentHashFactory())
-                            .stateTransfer()
-                                .fetchInMemoryState(false)
-                        .eviction()
-                            .strategy(EvictionStrategy.LIRS)
-                            .maxEntries(100000)
-                        .expiration()
-                            .lifespan(30, TimeUnit.MINUTES)
-                            .maxIdle(10, TimeUnit.MINUTES)
-                        .build();
-            } else {
-                defaultConfiguration = new ConfigurationBuilder()
-                        .clustering()
-                            .cacheMode(CacheMode.REPL_ASYNC)
-                            .async()
-                                .asyncMarshalling()
-                        .stateTransfer()
-                            .fetchInMemoryState(false)
-                        .eviction()
-                            .strategy(EvictionStrategy.LIRS)
-                            .maxEntries(100000)
-                        .expiration()
-                            .lifespan(30, TimeUnit.MINUTES)
-                            .maxIdle(10, TimeUnit.MINUTES)
-                        .build();
-            }
-        } else {
-            globalConfiguration = new GlobalConfigurationBuilder()
-                    .classLoader(KiWiCacheManager.class.getClassLoader())
-                    .globalJmxStatistics()
-                        .jmxDomain("org.apache.marmotta.kiwi")
-                        .allowDuplicateDomains(true)
-                    .build();
-
-            defaultConfiguration = new ConfigurationBuilder()
-                    .clustering()
-                        .cacheMode(CacheMode.LOCAL)
-                    .eviction()
-                        .strategy(EvictionStrategy.LIRS)
-                        .maxEntries(100000)
-                    .expiration()
-                        .lifespan(5, TimeUnit.MINUTES)
-                        .maxIdle(1, TimeUnit.MINUTES)
-                    .build();
-
-        }
-
-
-        cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
-        log.info("initialised cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host");
-
-        this.embedded = true;
-    }
-
-    /**
-     * Create a cache manager from an existing Infinispan cache manager.
-     *
-     * @param cacheManager
-     * @param kiWiConfiguration
-     */
-    public KiWiCacheManager(EmbeddedCacheManager cacheManager, KiWiConfiguration kiWiConfiguration, AdvancedExternalizer...externalizers) {
-        this.cacheManager = cacheManager;
-        this.globalConfiguration = cacheManager.getCacheManagerConfiguration();
-        this.defaultConfiguration = cacheManager.getDefaultCacheConfiguration();
-        this.kiWiConfiguration = kiWiConfiguration;
-
-        this.clustered = kiWiConfiguration.isClustered();
-
-        for(AdvancedExternalizer e : externalizers) {
-            this.globalConfiguration.serialization().advancedExternalizers().put(e.getId(), e);
-        }
-
-        log.info("initialised cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host");
-
-        this.embedded = false;
-    }
-
-    /**
-     * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
-     * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
-     *
-     * @return an EHCache Cache instance containing the node id -> node mappings
-     */
-    public Cache getNodeCache() {
-        if(nodeCache == null) {
-            Configuration nodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                    .eviction()
-                        .maxEntries(1000000)
-                    .expiration()
-                        .lifespan(60, TimeUnit.MINUTES)
-                        .maxIdle(30, TimeUnit.MINUTES)
-                    .build();
-            cacheManager.defineConfiguration(NODE_CACHE, nodeConfiguration);
-
-            nodeCache = cacheManager.getCache(NODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-        }
-
-        return nodeCache;
-    }
-
-    /**
-     * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
-     * construction of query results.
-     *
-     * @return
-     */
-    public Cache getTripleCache() {
-        if(tripleCache == null) {
-            Configuration tripleConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                    .clustering()
-                        .cacheMode(CacheMode.LOCAL)
-                    .eviction()
-                        .maxEntries(kiWiConfiguration.getTripleCacheSize())
-                    .expiration()
-                        .lifespan(60, TimeUnit.MINUTES)
-                        .maxIdle(30, TimeUnit.MINUTES)
-                    .build();
-            cacheManager.defineConfiguration(TRIPLE_CACHE, tripleConfiguration);
-
-            tripleCache = cacheManager.getCache(TRIPLE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-        }
-        return tripleCache;
-    }
-
-
-    /**
-     * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
-     * KiWiUriResources to avoid a database lookup.
-     *
-     * @return
-     */
-    public Cache getUriCache() {
-        if(uriCache == null) {
-            Configuration uriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                    .eviction()
-                        .maxEntries(kiWiConfiguration.getUriCacheSize())
-                    .build();
-            cacheManager.defineConfiguration(URI_CACHE, uriConfiguration);
-
-            uriCache = cacheManager.getCache(URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-        }
-        return uriCache;
-    }
-
-
-    /**
-     * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
-     * KiWiAnonResources to avoid a database lookup.
-     *
-     * @return
-     */
-    public Cache getBNodeCache() {
-        if(bnodeCache == null) {
-            Configuration bnodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                    .eviction()
-                        .maxEntries(kiWiConfiguration.getBNodeCacheSize())
-                    .build();
-            cacheManager.defineConfiguration(BNODE_CACHE, bnodeConfiguration);
-
-            bnodeCache = cacheManager.getCache(BNODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-        }
-        return bnodeCache;
-    }
-
-    /**
-     * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
-     * KiWiLiterals to avoid a database lookup.
-     *
-     * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
-     * @return
-     */
-    public Cache getLiteralCache() {
-        if(literalCache == null) {
-            Configuration literalConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                    .eviction()
-                        .maxEntries(kiWiConfiguration.getLiteralCacheSize())
-                    .build();
-            cacheManager.defineConfiguration(LITERAL_CACHE, literalConfiguration);
-
-            literalCache = cacheManager.getCache(LITERAL_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-        }
-        return literalCache;
-    }
-
-
-    /**
-     * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
-     * @return
-     */
-    public Cache getNamespaceUriCache() {
-        if(nsUriCache == null) {
-            if(clustered) {
-                Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                        .clustering()
-                            .cacheMode(CacheMode.REPL_ASYNC)
-                        .eviction()
-                            .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
-                        .expiration()
-                            .lifespan(1, TimeUnit.DAYS)
-                        .build();
-                cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
-            } else {
-                Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                        .eviction()
-                            .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
-                        .expiration()
-                            .lifespan(1, TimeUnit.HOURS)
-                        .build();
-                cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
-            }
-
-            nsUriCache = cacheManager.getCache(NAMESPACE_URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-        }
-        return nsUriCache;
-    }
-
-    /**
-     * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
-     * @return
-     */
-    public Cache getNamespacePrefixCache() {
-        if(nsPrefixCache == null) {
-            if(clustered) {
-                Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                        .clustering()
-                            .cacheMode(CacheMode.REPL_ASYNC)
-                        .eviction()
-                            .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
-                        .expiration()
-                            .lifespan(1, TimeUnit.DAYS)
-                        .build();
-                cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
-
-            } else {
-                Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                        .eviction()
-                            .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
-                        .expiration()
-                            .lifespan(1, TimeUnit.HOURS)
-                        .build();
-                cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
-
-            }
-            nsPrefixCache = cacheManager.getCache(NAMESPACE_PREFIX_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-        }
-        return nsPrefixCache;
-    }
-
-
-    /**
-     * Return the cache used by the KiWiLoader. Used for mapping from Sesame nodes to KiWi nodes.
-     * @return
-     */
-    public Cache getLoaderCache() {
-        if(loaderCache == null) {
-            Configuration loaderConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
-                    .eviction()
-                        .maxEntries(100000)
-                    .expiration()
-                        .lifespan(10, TimeUnit.MINUTES)
-                        .maxIdle(30, TimeUnit.SECONDS)
-                    .build();
-            cacheManager.defineConfiguration(LOADER_CACHE, loaderConfiguration);
-
-            loaderCache = cacheManager.getCache(LOADER_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-        }
-        return loaderCache;
-    }
-
-
-    /**
-     * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
-     * cache and should be used with care.
-     * @return
-     */
-    public Cache getRegistryCache() {
-        if(registryCache == null) {
-            if(clustered) {
-                Configuration registryConfiguration = new ConfigurationBuilder()
-                    .clustering()
-                        .cacheMode(CacheMode.REPL_SYNC)
-                        .sync()
-                            .replTimeout(15, TimeUnit.SECONDS)
-                    .eviction()
-                        .strategy(EvictionStrategy.NONE)
-                    .build();
-                cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
-            } else {
-                Configuration registryConfiguration = new ConfigurationBuilder()
-                    .clustering()
-                        .cacheMode(CacheMode.LOCAL)
-                    .eviction()
-                        .strategy(EvictionStrategy.NONE)
-                    .build();
-                cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
-            }
-
-            registryCache = cacheManager.getCache(REGISTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-        }
-        return registryCache;
-    }
-
-    /**
-     * Get the cache with the given name from the cache manager. Can be used to request additional
-     * caches from the cache manager that are not covered by explicit methods.
-     *
-     * @param name
-     * @return
-     */
-    public synchronized Cache getCacheByName(String name) {
-        if(!cacheManager.cacheExists(name)) {
-            cacheManager.defineConfiguration(name, new ConfigurationBuilder().read(defaultConfiguration).build());
-        }
-        return cacheManager.getCache(name).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-
-    }
-
-    /**
-     * Return the Infinispan cache manager used by the caching infrastructure.
-     *
-     * @return
-     */
-    public EmbeddedCacheManager getCacheManager() {
-        return cacheManager;
-    }
-
-    /**
-     * Return the global cache manager configuration used by the caching infrastructure.
-     * @return
-     */
-    public GlobalConfiguration getGlobalConfiguration() {
-        return globalConfiguration;
-    }
-
-    /**
-     * Return the default cache configuration used by the caching infrastructure.
-     * @return
-     */
-    public Configuration getDefaultConfiguration() {
-        return defaultConfiguration;
-    }
-
-    /**
-     * Clear all caches managed by this cache manager.
-     */
-    public void clear() {
-        Set<String> set =  cacheManager.getCacheNames();
-        Iterator<String> iterator =  set.iterator();
-        while(iterator.hasNext()){
-            String cacheName = iterator.next();
-            Cache<String,Object> cache = cacheManager.getCache(cacheName);
-            cache.clear();
-        }
-
-        nodeCache     = null;
-        tripleCache   = null;
-        uriCache      = null;
-        literalCache  = null;
-        bnodeCache    = null;
-        nsPrefixCache = null;
-        nsUriCache    = null;
-        loaderCache   = null;
-        registryCache = null;
-    }
-
-    /**
-     * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
-     */
-    public void shutdown() {
-        try {
-            if(embedded && cacheManager.getStatus() == ComponentStatus.RUNNING) {
-                log.warn("shutting down cache manager ...");
-//                if(cacheManager.getTransport() != null) {
-//                    log.info("... shutting down transport ...");
-//                    cacheManager.getTransport().stop();
-//                }
-                log.info("... shutting down main component ...");
-                cacheManager.stop();
-                log.info("... done!");
-            }
-        } catch (CacheException ex) {
-            log.warn("error shutting down cache: {}", ex.getMessage());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
deleted file mode 100644
index 0d0559b..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class StringLiteralExternalizer implements AdvancedExternalizer<KiWiStringLiteral> {
-
-    @Override
-    public Set<Class<? extends KiWiStringLiteral>> getTypeClasses() {
-        return Util.<Class<? extends KiWiStringLiteral>>asSet(KiWiStringLiteral.class);
-    }
-
-    @Override
-    public Integer getId() {
-        return ExternalizerIds.STRING_LITERAL;
-    }
-
-    @Override
-    public void writeObject(ObjectOutput output, KiWiStringLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeInt(object.getContent().length());
-        output.writeChars(object.getContent());
-        if(object.getLanguage() != null) {
-            output.writeInt(object.getLanguage().length());
-            output.writeChars(object.getLanguage());
-        } else {
-            output.writeInt(0);
-        }
-
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
-    }
-
-    @Override
-    public KiWiStringLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        int clen = input.readInt();
-        char[] content = new char[clen];
-        for(int i=0; i<clen; i++) {
-            content[i]=input.readChar();
-        }
-
-        int llen = input.readInt();
-        String lang = null;
-        if(llen > 0) {
-            char[] lb = new char[llen];
-            for(int i=0; i<llen; i++) {
-                lb[i] = input.readChar();
-            }
-            lang = new String(lb);
-        }
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiStringLiteral r = new KiWiStringLiteral(new String(content), lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
-        r.setId(id);
-
-        return r;
-    }
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/TripleExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/TripleExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/TripleExternalizer.java
deleted file mode 100644
index 22bfb6c..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/TripleExternalizer.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
-import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
-import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
-import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.sql.SQLException;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * An externalizer for Infinispan allowing to more efficiently transport triples by only serializing the node
- * IDs instead of the whole nodes.
- */
-public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
-
-    private static Logger log = LoggerFactory.getLogger(TripleExternalizer.class);
-
-    private KiWiPersistence persistence;
-
-    public TripleExternalizer(KiWiPersistence persistence) {
-        this.persistence = persistence;
-    }
-
-    @Override
-    public Set<Class<? extends KiWiTriple>> getTypeClasses() {
-        return Util.<Class<? extends KiWiTriple>>asSet(KiWiTriple.class);
-    }
-
-    @Override
-    public Integer getId() {
-        return 13;
-    }
-
-    @Override
-    public void writeObject(ObjectOutput output, KiWiTriple object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeLong(object.getSubject().getId());
-        output.writeLong(object.getPredicate().getId());
-        output.writeLong(object.getObject().getId());
-        output.writeLong(object.getContext() != null ? object.getContext().getId() : -1L);
-        output.writeLong(object.getCreator() != null ? object.getCreator().getId() : -1L);
-        output.writeBoolean(object.isDeleted());
-        output.writeBoolean(object.isInferred());
-        output.writeBoolean(object.isNewTriple());
-        output.writeLong(object.getCreated().getTime());
-        if(object.getDeletedAt() != null) {
-            output.writeLong(object.getDeletedAt().getTime());
-        } else {
-            output.writeLong(0);
-        }
-    }
-
-    @Override
-    public KiWiTriple readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        try {
-            KiWiConnection con = persistence.getConnection();
-            try {
-                KiWiTriple result = new KiWiTriple();
-                result.setId(input.readLong());
-
-                long[] nodeIds = new long[5];
-                for(int i=0; i<5; i++) {
-                    nodeIds[0] = input.readLong();
-                }
-                KiWiNode[] nodes = con.loadNodesByIds(nodeIds);
-
-                result.setSubject((KiWiResource) nodes[0]);
-                result.setPredicate((KiWiUriResource) nodes[1]);
-                result.setObject(nodes[2]);
-
-                if(nodes[3] != null) {
-                    result.setContext((KiWiResource) nodes[3]);
-                }
-                if(nodes[4] != null) {
-                    result.setCreator((KiWiResource) nodes[4]);
-                }
-
-                result.setDeleted(input.readBoolean());
-                result.setInferred(input.readBoolean());
-                result.setNewTriple(input.readBoolean());
-
-                result.setCreated(new Date(input.readLong()));
-
-                long deletedAt = input.readLong();
-                if(deletedAt > 0) {
-                    result.setDeletedAt(new Date(deletedAt));
-                }
-
-
-                return result;
-            } finally {
-                con.commit();
-                con.close();
-            }
-        } catch (SQLException ex) {
-            throw new IOException(ex);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
deleted file mode 100644
index 3139db1..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class UriExternalizer implements AdvancedExternalizer<KiWiUriResource> {
-
-    @Override
-    public Set<Class<? extends KiWiUriResource>> getTypeClasses() {
-        return Util.<Class<? extends KiWiUriResource>>asSet(KiWiUriResource.class);
-    }
-
-    @Override
-    public Integer getId() {
-        return ExternalizerIds.URI;
-    }
-
-    @Override
-    public void writeObject(ObjectOutput output, KiWiUriResource object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeInt(object.stringValue().length());
-        output.writeChars(object.stringValue());
-        output.writeLong(object.getCreated().getTime());
-    }
-
-    @Override
-    public KiWiUriResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        int len = input.readInt();
-
-        char[] uri = new char[len];
-        for(int i=0; i<len; i++) {
-            uri[i] = input.readChar();
-        }
-
-        Date created = new Date(input.readLong());
-
-        KiWiUriResource r = new KiWiUriResource(new String(uri),created);
-        r.setId(id);
-
-        return r;
-    }
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
index 3658d25..a445112 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
@@ -91,6 +91,14 @@ public class KiWiConfiguration {
     private String[] fulltextLanguages;
 
 
+    /**
+     * Fully qualified class name of the cache manager factory to use. Falls back to the Guava
+     * cache manager if not found
+     */
+    private String cacheManagerFactory = "org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory";
+
+    private int nodeCacheSize = 1000000;
+
     private int uriCacheSize = 500000;
 
     private int bNodeCacheSize = 10000;
@@ -289,6 +297,37 @@ public class KiWiConfiguration {
 
 
     /**
+     * Fully qualified class name of the cache manager factory to use. Falls back to the Guava
+     * cache manager if not found
+     */
+    public String getCacheManagerFactory() {
+        return cacheManagerFactory;
+    }
+
+    /**
+     * Fully qualified class name of the cache manager factory to use. Falls back to the Guava
+     * cache manager if not found
+     */
+    public void setCacheManagerFactory(String cacheManagerFactory) {
+        this.cacheManagerFactory = cacheManagerFactory;
+    }
+
+    /**
+     * The maximum size of the node ID cache used by the KiWiValueFactory (default: 1000000)
+     * @return
+     */
+    public int getNodeCacheSize() {
+        return nodeCacheSize;
+    }
+
+    /**
+     * The maximum size of the node ID cache used by the KiWiValueFactory (default: 1000000)
+     */
+    public void setNodeCacheSize(int nodeCacheSize) {
+        this.nodeCacheSize = nodeCacheSize;
+    }
+
+    /**
      * The maximum size of the literal cache used by the KiWiValueFactory (default: 100000)
      * @return
      */

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
index 5cd363e..28edf7f 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
@@ -18,8 +18,6 @@
 package org.apache.marmotta.kiwi.persistence;
 
 import com.google.common.base.Preconditions;
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
 import com.google.common.primitives.Longs;
 import info.aduna.iteration.*;
 import org.apache.commons.lang3.math.NumberUtils;
@@ -27,13 +25,12 @@ import org.apache.marmotta.commons.sesame.model.LiteralCommons;
 import org.apache.marmotta.commons.sesame.model.Namespaces;
 import org.apache.marmotta.commons.sesame.tripletable.TripleTable;
 import org.apache.marmotta.commons.util.DateUtils;
-import org.apache.marmotta.kiwi.caching.KiWiCacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManager;
 import org.apache.marmotta.kiwi.config.KiWiConfiguration;
 import org.apache.marmotta.kiwi.exception.ResultInterruptedException;
 import org.apache.marmotta.kiwi.model.rdf.*;
 import org.apache.marmotta.kiwi.persistence.util.ResultSetIteration;
 import org.apache.marmotta.kiwi.persistence.util.ResultTransformerFunction;
-import org.infinispan.Cache;
 import org.openrdf.model.Literal;
 import org.openrdf.model.Resource;
 import org.openrdf.model.Statement;
@@ -65,47 +62,47 @@ public class KiWiConnection implements AutoCloseable {
 
     protected KiWiPersistence  persistence;
 
-    protected KiWiCacheManager cacheManager;
+    protected CacheManager cacheManager;
 
     protected TripleTable<KiWiTriple> tripleBatch;
 
     /**
      * Cache nodes by database ID
      */
-    private Cache<Long,KiWiNode> nodeCache;
+    private Map<Long,KiWiNode> nodeCache;
 
     /**
      * Cache triples by database ID
      */
-    private Cache<Long,KiWiTriple> tripleCache;
+    private Map<Long,KiWiTriple> tripleCache;
 
 
     /**
      * Cache URI resources by uri
      */
-    private Cache<Long,KiWiUriResource> uriCache;
+    private Map<String,KiWiUriResource> uriCache;
 
 
     /**
      * Cache BNodes by BNode ID
      */
-    private Cache<Long,KiWiAnonResource> bnodeCache;
+    private Map<String,KiWiAnonResource> bnodeCache;
 
     /**
      * Cache literals by literal cache key (LiteralCommons#createCacheKey(String,Locale,URI))
      */
-    private Cache<String,KiWiLiteral> literalCache;
+    private Map<String,KiWiLiteral> literalCache;
 
 
     /**
      * Look up namespaces by URI
      */
-    private Cache<String,KiWiNamespace> namespaceUriCache;
+    private Map<String,KiWiNamespace> namespaceUriCache;
 
     /**
      * Look up namespaces by prefix
      */
-    private Cache<String,KiWiNamespace> namespacePrefixCache;
+    private Map<String,KiWiNamespace> namespacePrefixCache;
 
     /**
      * Cache instances of locales for language tags
@@ -141,7 +138,7 @@ public class KiWiConnection implements AutoCloseable {
 
     private int QUERY_BATCH_SIZE = 1024;
 
-    public KiWiConnection(KiWiPersistence persistence, KiWiDialect dialect, KiWiCacheManager cacheManager) throws SQLException {
+    public KiWiConnection(KiWiPersistence persistence, KiWiDialect dialect, CacheManager cacheManager) throws SQLException {
         this.cacheManager = cacheManager;
         this.dialect      = dialect;
         this.persistence  = persistence;
@@ -211,7 +208,7 @@ public class KiWiConnection implements AutoCloseable {
      * Return the cache manager used by this connection
      * @return
      */
-    public KiWiCacheManager getCacheManager() {
+    public CacheManager getCacheManager() {
         return cacheManager;
     }
 
@@ -571,7 +568,7 @@ public class KiWiConnection implements AutoCloseable {
         Preconditions.checkNotNull(uri);
 
         // look in cache
-        KiWiUriResource element = uriCache.get(createCacheKey(uri));
+        KiWiUriResource element = uriCache.get(uri);
         if(element != null) {
             return element;
         }
@@ -617,7 +614,7 @@ public class KiWiConnection implements AutoCloseable {
      */
     public KiWiAnonResource loadAnonResource(String id) throws SQLException {
         // look in cache
-        KiWiAnonResource element = bnodeCache.get(createCacheKey(id));
+        KiWiAnonResource element = bnodeCache.get(id);
         if(element != null) {
             return element;
         }
@@ -1272,7 +1269,6 @@ public class KiWiConnection implements AutoCloseable {
 
                     if (triple.getId() < 0) {
                         log.warn("attempting to remove non-persistent triple: {}", triple);
-                        removeCachedTriple(triple);
                     } else {
                         if (batchCommit) {
                             // need to remove from triple batch and from database
@@ -1302,8 +1298,8 @@ public class KiWiConnection implements AutoCloseable {
 
 
                         }
-                        removeCachedTriple(triple);
                     }
+                    removeCachedTriple(triple);
                 }
 
                 return null;
@@ -2035,26 +2031,26 @@ public class KiWiConnection implements AutoCloseable {
 
     private void cacheNode(KiWiNode node) {
         if(node.getId() >= 0) {
-            nodeCache.putForExternalRead(node.getId(), node);
+            nodeCache.put(node.getId(), node);
         }
         if(node instanceof KiWiUriResource) {
-            uriCache.putForExternalRead(createCacheKey(node.stringValue()), (KiWiUriResource) node);
+            uriCache.put(node.stringValue(), (KiWiUriResource) node);
         } else if(node instanceof KiWiAnonResource) {
-            bnodeCache.putForExternalRead(createCacheKey(node.stringValue()), (KiWiAnonResource) node);
+            bnodeCache.put(node.stringValue(), (KiWiAnonResource) node);
         } else if(node instanceof KiWiLiteral) {
-            literalCache.putForExternalRead(LiteralCommons.createCacheKey((Literal) node), (KiWiLiteral) node);
+            literalCache.put(LiteralCommons.createCacheKey((Literal) node), (KiWiLiteral) node);
         }
     }
 
     private void cacheTriple(KiWiTriple triple) {
         if(triple.getId() >= 0) {
-            tripleCache.putForExternalRead(triple.getId(), triple);
+            tripleCache.put(triple.getId(), triple);
         }
     }
 
     private void removeCachedTriple(KiWiTriple triple) {
         if(triple.getId() >= 0) {
-            tripleCache.removeAsync(triple.getId());
+            tripleCache.remove(triple.getId());
         }
     }
 
@@ -2569,11 +2565,5 @@ public class KiWiConnection implements AutoCloseable {
 
     }
 
-    private static Long createCacheKey(String svalue) {
-        Hasher hasher = Hashing.goodFastHash(64).newHasher();
-        hasher.putString(svalue);
-        return hasher.hash().asLong();
-    }
-
 
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
index a3cf60c..6d81065 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
@@ -17,7 +17,9 @@
  */
 package org.apache.marmotta.kiwi.persistence;
 
-import org.apache.marmotta.kiwi.caching.*;
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
+import org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory;
 import org.apache.marmotta.kiwi.config.KiWiConfiguration;
 import org.apache.marmotta.kiwi.generator.IDGenerator;
 import org.apache.marmotta.kiwi.generator.SnowflakeIDGenerator;
@@ -25,8 +27,6 @@ import org.apache.marmotta.kiwi.persistence.util.ScriptRunner;
 import org.apache.marmotta.kiwi.sail.KiWiValueFactory;
 import org.apache.tomcat.jdbc.pool.DataSource;
 import org.apache.tomcat.jdbc.pool.PoolProperties;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.manager.EmbeddedCacheManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -55,7 +55,7 @@ public class KiWiPersistence {
 
     private PoolProperties        poolConfig;
 
-    private KiWiCacheManager      cacheManager;
+    private CacheManager cacheManager;
 
     private KiWiGarbageCollector  garbageCollector;
 
@@ -82,9 +82,6 @@ public class KiWiPersistence {
 
     private boolean         initialized = false;
 
-    // in case the cache manager comes from outside, it is passed over here
-    private EmbeddedCacheManager infinispan;
-
     @Deprecated
     public KiWiPersistence(String name, String jdbcUrl, String db_user, String db_password, KiWiDialect dialect) {
         this(new KiWiConfiguration(name,jdbcUrl,db_user,db_password,dialect));
@@ -95,12 +92,6 @@ public class KiWiPersistence {
         this.maintenance = false;
     }
 
-    public KiWiPersistence(KiWiConfiguration configuration, EmbeddedCacheManager infinispan) {
-        this.configuration = configuration;
-        this.maintenance = false;
-        this.infinispan = infinispan;
-    }
-
 
     public void initialise() {
         // init JDBC connection pool
@@ -132,27 +123,21 @@ public class KiWiPersistence {
         return configuration.getDialect();
     }
 
-    public KiWiCacheManager getCacheManager() {
+    public CacheManager getCacheManager() {
         return cacheManager;
     }
 
 
     private void initCachePool() {
-        AdvancedExternalizer[] externalizers =  new AdvancedExternalizer[] {
-                new TripleExternalizer(this),
-                new UriExternalizer(),
-                new BNodeExternalizer(),
-                new StringLiteralExternalizer(),
-                new DateLiteralExternalizer(),
-                new BooleanLiteralExternalizer(),
-                new IntLiteralExternalizer(),
-                new DoubleLiteralExternalizer()
-        };
-
-        if(infinispan != null) {
-            cacheManager = new KiWiCacheManager(infinispan,configuration, externalizers);
-        } else {
-            cacheManager = new KiWiCacheManager(configuration, externalizers);
+
+        try {
+            Class factory = Class.forName(configuration.getCacheManagerFactory());
+            cacheManager = ((CacheManagerFactory)factory.newInstance()).createCacheManager(configuration);
+        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
+            log.warn("cache manager factory {} not found on classpath (error: {}); falling back to Guava in-memory cache backend!", configuration.getCacheManagerFactory(), e.getMessage());
+
+            CacheManagerFactory factory = new GuavaCacheManagerFactory();
+            cacheManager = factory.createCacheManager(configuration);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java
index 8f81531..7e4d14d 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java
@@ -18,8 +18,7 @@
 package org.apache.marmotta.kiwi.persistence.registry;
 
 import org.apache.marmotta.commons.sesame.tripletable.IntArray;
-import org.apache.marmotta.kiwi.caching.KiWiCacheManager;
-import org.infinispan.Cache;
+import org.apache.marmotta.kiwi.caching.CacheManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,13 +37,13 @@ public class CacheTripleRegistry implements KiWiTripleRegistry {
 
     private static Logger log = LoggerFactory.getLogger(CacheTripleRegistry.class);
 
-    private Cache<Long,Long> cache;
+    private Map<Long,Long> cache;
 
 
     private Map<Long,List<Long>>  transactions;
 
 
-    public CacheTripleRegistry(KiWiCacheManager cacheManager) {
+    public CacheTripleRegistry(CacheManager cacheManager) {
         cache        = cacheManager.getRegistryCache();
         transactions = new HashMap<>();
 
@@ -65,7 +64,7 @@ public class CacheTripleRegistry implements KiWiTripleRegistry {
             transaction = new ArrayList<>();
             transactions.put(transactionId, transaction);
         }
-        cache.putForExternalRead(key.longHashCode(),tripleId);
+        cache.put(key.longHashCode(), tripleId);
         transaction.add(key.longHashCode());
     }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
index ea5fb79..899b941 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
@@ -20,7 +20,6 @@ package org.apache.marmotta.kiwi.sail;
 import org.apache.marmotta.kiwi.config.KiWiConfiguration;
 import org.apache.marmotta.kiwi.persistence.KiWiDialect;
 import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
-import org.infinispan.manager.EmbeddedCacheManager;
 import org.openrdf.model.ValueFactory;
 import org.openrdf.sail.SailException;
 import org.openrdf.sail.helpers.NotifyingSailBase;
@@ -98,10 +97,6 @@ public class KiWiStore extends NotifyingSailBase {
         this(new KiWiPersistence(configuration), configuration.getDefaultContext(), configuration.getInferredContext());
     }
 
-    public KiWiStore(KiWiConfiguration configuration, EmbeddedCacheManager infinispan) {
-        this(new KiWiPersistence(configuration, infinispan), configuration.getDefaultContext(), configuration.getInferredContext());
-    }
-
     /**
      * Do store-specific operations to initialize the store. The default
      * implementation of this method does nothing.

http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory b/libraries/kiwi/kiwi-triplestore/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
new file mode 100644
index 0000000..5d45ff7
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
@@ -0,0 +1 @@
+org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory
\ No newline at end of file