客户端需要在服务器上配置的自定义 CacheStore

Client needs custom CacheStore that is configured on server

我有一个使用自定义 CacheStore 实现的 client/server 测试。我想要在服务器节点上而不是在客户端节点上自定义 CacheStore,但 Ignite 正在尝试在客户端上加载自定义实现。有没有办法避免这种情况?

服务器代码:

IgniteConfiguration igniteCfg = new IgniteConfiguration();
Ignite ignite = Ignition.start(igniteCfg);
CacheConfiguration<String, String> cacheCfg = new CacheConfiguration<>("test");
cacheCfg.setReadThrough(true);
cacheCfg.setCacheStoreFactory(new CacheStoreFactory());
IgniteCache<String, String> cache = ignite.getOrCreateCache(cacheCfg);

缓存存储区:

public class CacheStoreFactory implements Factory<CacheStore<? super String, ? super String>> {
    @Override
    public CacheStore<? super String, ? super String> create() {
        return new CacheStoreAdapter<String, String>() {
            @Override
            public String load(String key) throws CacheLoaderException {
                System.out.println("load: key=" + key);
                return key;
            }
            @Override
            public void write(Entry<? extends String, ? extends String> entry) throws CacheWriterException {
            }
            @Override
            public void delete(Object key) throws CacheWriterException {
            }
        };
    }
}

客户:

IgniteConfiguration igniteCfg = new IgniteConfiguration();
igniteCfg.setClientMode(true);
Ignite ignite = Ignition.start(igniteCfg);
CacheConfiguration<String, String> cacheCfg = new CacheConfiguration<>("test");
IgniteCache<String, String> cache = ignite.getOrCreateCache(cacheCfg);
String value = cache.get("someKey");

在服务器上正确调用了 CacheStore,客户端似乎工作正常,但客户端记录了这个错误:

Caused by: java.lang.ClassNotFoundException: org.dalsing.ignite.server.test.CacheStoreFactory

TRANSACTIONAL 缓存需要客户端上的缓存存储。对于 ATOMIC 缓存(这是默认模式),不需要它,因此您可以安全地忽略异常。