java - Apache Ignite mongo configuration using spring -
i introducing apache ignite in our application cache system computation. have configured spring application using following configuration class.
@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; } }
using like
@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; }
now want add write-through , read-through feature. not find documentation connect ignite mongo.
the idea not talk db directly through ignite using write behind feature.
edit-----------------------
as suggested implemented
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); } }
and added cachestore cache configuration below :
<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 database enabled. --> <property name="writethrough" value="true"/> <!-- enable database batching. --> <!-- sets flag indicating whether write-behind 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>
but getting class cast exception
java.lang.classcastexception: org.springframework.cache.interceptor.simplekey cannot cast java.lang.long @ in.per.amt.ignite.cache.channelcachestore.load(channelcachestore.java:19)
you can have kind of backing database implementing cachestore
interface:
Comments
Post a Comment