GithubHelp home page GithubHelp logo

infinispan.playground.custom-stores's Introduction

Infinispan Customized Cache Stores

Author: Wolf-Dieter Fink Level: Advanced Technologies: Infinispan, Hot Rod, Query, Ickle

What is it?

Different examples how to implement and configure customized cache stores.

Prepare a server instance

Simple start a Infinispan or JDG server and add the following caches.

Build and Run the example

  1. Type this command to build and deploy the archive:

     mvn clean package
    
  2. Deploy the CacheStore implementation and use the HotRod client to access the cache

    Custom Cache Loader

    This example use a simple CacheLoader implementation to retrieve data from a 'persistence'. Copy the CacheLoader/target/CacheLoader.jar to the deployment folder of your server installation. Add the following XML configuration to the clustered.xml

                <distributed-cache name="PersonCacheWithLoader">
                    <encoding>
                        <key media-type="application/x-protostream"/>
                        <value media-type="application/x-protostream"/>
                    </encoding>
                    <persistence>
                        <store class="org.infinispan.wfink.playground.cacheloader.impl.CustomCacheLoader">
                            <property name="name">Wolf Fink</property>
                            <property name="age">42</property>
                        </store>
                    </persistence>
                </distributed-cache>
 So each get which load from the 'persistence' will return the person 'Wolf Fink' with different ID's
 As there is no persistence behind and no writer nothing will survive a restart.

Custom Cache Writer

 This example implement CacheLoader and CacheWriter to retrieve and store the data from/to a 'persistence'.

 Copy the `CacheWriter/target/CacheWriter.jar` to the deployment folder of your server installation.
 Add the following XML configuration to the clustered.xml, change or remove the properties as needed.
 For the database you need to add the datasource and driver and add the driver as module or deployment as well.
                <distributed-cache name="PersonCacheWithLoader">
                    <encoding>
                        <key media-type="application/x-protostream"/>
                        <value media-type="application/x-protostream"/>
                    </encoding>
                    <persistence>
                        <store class="org.infinispan.wfink.playground.cacheloader.impl.CustomCacheWriter">
                            <property name="datasource">java:jboss/datasources/mySQLDS</property>
                            <property name="database">jdg</property>
                            <property name="table">MyPerson</property>
                        </store>
                    </persistence>
                </distributed-cache>
 So each get which load from the persistence, a put will store the Person to the database.
 The implemented SQL is simple and should work for all kind of database.

HotRodClient

 The client will prompt to manipulate cache data.
 run the script 'runClient <path/to/infinispan/remote/libraries>'
 you are able to read and manipulate the cache.
 Depending on the installed Store implementation you can check the behaviour.
 If 'org.infninispan.wfink' category is set to trace the server will log messages for each action.
 Also the person.proto need to be registered for the client side and the server as this is not done by the cache loader implementation.

infinispan.playground.custom-stores's People

Contributors

wfink avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.