简体   繁体   中英

Setting Neo4j cache

I'm using Neo4j 1.9.4 for a project and I run into a strange behavior :

I have this piece of code that works well. I've set the classpath with a ivy file and all is ok.

public static void main(String[] args) {
    // the cache providers
    ArrayList<CacheProvider> cacheList = new ArrayList<CacheProvider>();
    System.out.println("Creating db configuration");
    cacheList.add(new SoftCacheProvider());

    // the kernel extensions
    LuceneKernelExtensionFactory lucene = new LuceneKernelExtensionFactory();
    List<KernelExtensionFactory<?>> extensions = new 
        ArrayList<KernelExtensionFactory<?>>();
    extensions.add(lucene);

    // the database setup
    GraphDatabaseFactory gdbf = new GraphDatabaseFactory();
    gdbf.setKernelExtensions(extensions);
    gdbf.setCacheProviders(cacheList);
    GraphDatabaseService db = gdbf.newEmbeddedDatabase("/tmp/test");
}

The problem is when I try to change cacheList.add(new SoftCacheProvider()) into cacheList.add(new WeakCacheProvider()) I get the following error :

java.lang.IllegalArgumentException: No provider for cache type 'soft'. Cache providers are loaded using java service loading where they register themselves in resource (plain-text) files found on the class path under META-INF/services/org.neo4j.kernel.impl.cache.CacheProvider. This missing provider may have been caused by either such a missing registration, or by the lack of the provider class itself.
    at org.neo4j.kernel.InternalAbstractGraphDatabase.create(InternalAbstractGraphDatabase.java:356)
    at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:252)
    at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:106)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:88)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:207)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69)
    at ttt.App.main(App.java:34)

There is also the same error if I try to use a NoChacheProvider or a StrongCacheProvider.

I tried to add the file META-INF/services/org.neo4j.kernel.impl.cache.CacheProvider with the following content but it doesn't change anything.

org.neo4j.kernel.impl.cache.WeakCacheProvider
org.neo4j.kernel.impl.cache.SoftCacheProvider
org.neo4j.kernel.impl.cache.NoCacheProvider
org.neo4j.kernel.impl.cache.StrongCacheProvider

Do you have any idea of what is going on ? I don't understand why there is only one cache provider type that is working.

Please note that I have to use Neo4j 1.9.4 and I can't change it.

Edit : my project is a basic eclipse plug-in project without any other dependecies

Edit2 : an other interesting point is if I try to configure the database with a Map<String,String> I get the same error, even for <"cache_type","soft"> .

public static void main(String[] args) {
    Map<String,String> config = new HashMap<String,String>();
    config.put("cache_type", "soft");
    GraphDatabaseService db = null;
    db = new EmbeddedGraphDatabase("/tmp/test", config, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
}

java.lang.IllegalArgumentException: No provider for cache type 'soft'. Cache providers are loaded using java service loading where they register themselves in resource (plain-text) files found on the class path under META-INF/services/org.neo4j.kernel.impl.cache.CacheProvider. This missing provider may have been caused by either such a missing registration, or by the lack of the provider class itself.
    at org.neo4j.kernel.InternalAbstractGraphDatabase.create(InternalAbstractGraphDatabase.java:356)
    at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:252)
    at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:106)
    at ttt.App.main(App.java:36)

What about trying to specify it directly in the config, with something like:

GraphDatabaseService db = gdbf.newEmbeddedDatabaseBuilder('path/to/db').setConfig(GraphDatabaseSettings.cache_type, WeakCacheProvider.NAME).newGraphDatabase()

Granted, I've not tried this in 1.9.4, but, maybe it's worth a shot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM