Performance Zone is brought to you in partnership with:

Manik Surtani is a core R&D engineer at JBoss and project lead on JBoss Cache. He has a background in artificial intelligence and neural networks, a field he left behind when he moved from academic circles to the commercial world. Since then, he's been working with Java-related technologies, first for a startup, focusing on knowledge management and information exchange. He later worked for a large London-based consultancy as a tech lead focused on e-commerce applications on large J2EE and peer-to-peer technology. Manik is a strong proponent of open source development methodologies, ethos, and collaborative processes, and often speaks at Java User Groups around the world. Manik is a DZone MVB and is not an employee of DZone and has posted 39 posts at DZone. You can read more from them at their website. View Full User Profile

Using MongoDB as a cache store

06.05.2013
| 3528 views |
  • submit to reddit

 With the 5.3 release, there is a brand new feature. I'm glad to announce that you will be able to use MongoDB as a cache store.

For those who don't know MongoDB, it's an open-source document oriented NoSQL database developped by 10Gen. You can more information about it on http://www.mongodb.org/.

The question you have right now, it probably, how to use it cool cache store ? Simple, as for the other cache store you have to add a loader in your Infinispan configuration file.

Here is an exemple:

 <loaders>
      <mongodbStore xmlns="urn:infinispan:config:mongodb:5.3" >
            <connection host="localhost" port="27017" timeout="2000" acknowledgment="0"/>
            <authentication username="mongoUser" password="mongoPass" />
            <storage database="infinispan_test_database" collection="infispan_cachestore" />
    </mongodbStore>
 </loaders>
ConfigurationBuilder b = new ConfigurationBuilder();
b.loaders().addStore(MongoDBCacheStoreConfigurationBuilder.class)
   .host( "localhost" )
   .port( 27017 )
   .timeout( 1500 )
   .acknowledgment( 0 )
   .username( "mongoDBUSer" )
   .password( "mongoBDPassword" )
   .database( "infinispan_cachestore" )
   .collection( "entries" );
 
final Configuration config = b.build();
MongoDBCacheStoreConfiguration store = (MongoDBCacheStoreConfiguration) config.loaders().cacheLoaders().get(0);
For more information about the configuration possibilities (default values, options, etc) , you can refer to the documentation page
Published at DZone with permission of Manik Surtani, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)