Over a million developers have joined DZone.

Using MongoDB as a cache store

· Performance Zone

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

 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

Learn tips and best practices for optimizing your capacity management strategy with the Market Guide for Capacity Management, brought to you in partnership with BMC.

Topics:

Published at DZone with permission of Manik Surtani, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}