Apache使用spring Ignite mongo配置

时间:2016-08-29 11:04:40

标签: java spring spring-mvc ignite

我在我们的应用程序中将Apache Ignite作为缓存系统和计算引入。我使用以下配置类配置了spring应用程序。

def with_pagination
    @post = Post.find_by_slug(params[:post_id])
end

一样使用它
@Configuration
@EnableCaching
public class IgniteConfig {

    @Value("${ignite.config.path}")
    private String ignitePath;

    @Bean(name="cacheManager")
    public SpringCacheManager cacheManager(){
        SpringCacheManager springCacheManager = new SpringCacheManager();
        springCacheManager.setConfigurationPath(ignitePath);
        return springCacheManager;
    }
}

现在我想添加直写和直读功能。我找不到任何连接点燃到mongo的文档。

这个想法不是直接与db通信,而是通过使用write behind功能点燃。

EDIT -----------------------

正如我所建议的那样实施

@Override
@Cacheable("cache1")
public List<Channel>  getAllChannels(){
    List<Channel> list = new ArrayList<Channel>();
    Channel c1 = new Channel("1",1);
    Channel c2 = new Channel("2",2);
    Channel c3 = new Channel("3",3);
    Channel c4 = new Channel("4",4);
    list.add(c1);
    list.add(c2);
    list.add(c3);
    list.add(c4);
    return list;
}

并将此CacheStore添加到缓存配置中,如下所示:

public class ChannelCacheStore extends CacheStoreAdapter<Long, Channel> implements Serializable {

    @Override
    public Channel load(Long key) throws CacheLoaderException {
        return getChannelDao().findOne(Channel.mongoChannelCode, key);
    }

    @Override
    public void write(Cache.Entry<? extends Long, ? extends Channel> entry) throws CacheWriterException {
        getChannelDao().save(entry.getValue());
    }

    @Override
    public void delete(Object key) throws CacheWriterException {
        throw new UnsupportedOperationException("Delete not supported");
    }

    private ChannelDao getChannelDao(){
        return SpringContextUtil.getApplicationContext().getBean(ChannelDao.class);
    }
}

但是现在正在获得类强制转换

<property name="cacheConfiguration">
        <list>
            <bean class="org.apache.ignite.configuration.CacheConfiguration">
                <property name="name" value="channelCache"/>
                <property name="cacheMode" value="PARTITIONED"/>
                <property name="atomicityMode" value="ATOMIC"/>
                <property name="backups" value="1"/>
                <property name="readThrough" value="true"/>
                <!-- Sets flag indicating whether write to database is enabled. -->
                <property name="writeThrough" value="true"/>
                <!-- Enable database batching. --> 
                <!-- Sets flag indicating whether write-behind is enabled. -->
                <property name="writeBehindEnabled" value="true"/>
                <property name="cacheStoreFactory">
                    <bean class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
                        <constructor-arg>
                            <bean class="in.per.amt.ignite.cache.ChannelCacheStore"></bean>
                        </constructor-arg>
                    </bean>
                </property>
            </bean>
        </list>
    </property>

3 个答案:

答案 0 :(得分:3)

您可以通过实施session.get('__AUTH_USER').find({ approvedModules : "examplemodule"}) interface:

来拥有任何类型的支持数据库

https://apacheignite.readme.io/docs/persistent-store

答案 1 :(得分:0)

您是否尝试过设置密钥生成器?

@CacheConfig(cacheNames =&#34; cache1&#34;,keyGenerator =&#34; simpleKeyGenerator&#34;)

https://github.com/spring-projects/spring-boot/issues/3625

答案 2 :(得分:0)

所以在您共享的以下代码行中,

@Cacheable("cache1")
public List<Channel>  getAllChannels(){

@Cacheable注释用于不接受任何参数的方法。 Spring缓存使用参数(如果是基本数据类型)作为缓存的键(响应obj作为值)。我相信这会使缓存失效。