10 Replies Latest reply on May 23, 2013 4:41 AM by rshanker

    Configure mutiple cache stores

      Hi all,
      If each cachestore-scheme is applicable only for DAO class then how do we configure for multiple DAOs?
      Cachestore-scheme does mentions about the class-scheme, but no clarity on the class-scheme is multiple or single AND none mentions how to configure multiple class-schemes in a single cache store or multiple cachestore-schemes for a single cache-scheme?
      None of the configuration documents covers this?...

      Ravi Shanker
        • 1. Re: Configure mutiple cache stores
          Hi Ravi,

          So that we can give a better answer, can you tell us why do you want multiple cache stores?

          • 2. Re: Configure mutiple cache stores
            hi JK,

            I have many different DB tables data which is required to be cached, to achieve this i was looking for multiple cache stores.

            like i have 1 table for Profile maintenance and few more tables for user application usage maintenance.

            ~Ravi Shanker
            • 3. Re: Configure mutiple cache stores
              Hi Ravi,

              I presume you mean you have multiple caches that map to a single cache scheme in the configuration file but you want different cache stores for each of those caches.

              There are a few ways you could do this but all of them usually use parameters in the configuration. If you look at the documentation on cache stores you will see examples of this. E.G http://docs.oracle.com/cd/E24290_01/coh.371/e22837/cache_rtwtwbra.htm#CFHBFIFB

              If you look at that example you will see the cache-store-scheme looks like this
              You can see above that the cache store class is called com.company.MyCacheStore and there is an init-param of type String that has a value of {cache-name} which is a macro that Coherence will convert into the name of the cache that the cache store is being created for. Each cache has a different instance of the com.company.MyCacheStore class created for it. The com.company.MyCacheStore class has a single constructor like this:
              private String cacheName;
              public MyCacheStore(String cacheName)
                  this.cacheName = cacheName;
              When the constructor is called the name of the cache is passed in, then in the various methods of the cache store, you know what cache you are dealing with and what SQL you need to execute.

              • 4. Re: Configure mutiple cache stores
                Thanks JK,
                I have gone through this, but I didnt find how to pass these init parameter's value pro-grammatically? that's where i got stuck?

                Ravi Shanker
                • 5. Re: Configure mutiple cache stores

                  You do not pass the init-parameters programatically. In the example above the cache-store-scheme has a single init-param and because the value of this init-param is a Coherence macro {cache-name} then Coherence will automatically inject the cache name into the constructor of the cache store when it is created for a cache. You do not have to do anything in your code. All you have to do is write a cache store class.

                  • 6. Re: Configure mutiple cache stores
                    As per the your update, if im not wrong i need to configure a cache-scheme for each cache store. Please confirm.

                    Ravi Shanker
                    • 7. Re: Configure mutiple cache stores

                      Ideally, you should configure a <class-factory-name> in your <class-scheme> and pass a parameter as the {cache-name} and other constructor arguments as required and let you factory instantiate the cacheStore. In that way, you can have only factory configured for multiple caches.


                      • 8. Re: Configure mutiple cache stores
                        Hi NJ,

                        sorry for being too specific. Im just trying to understand how this works in the implementation level.

                        How does the cache-factory to {cache-name} will be working?

                        In application i refer to the cache and start put and gets on the cache.
                        Now how does the coherence will get to know which key inserted into the Cache is applicable for a certain {cache-name} macro??...

                        Basically i trying to understand how coherence works internally and suitable for my application (in improving performance) as i have to provide a demo on this before i can ask for a licensed version :)
                        • 9. Re: Configure mutiple cache stores

                          OK, here it is in simple terms...
                          <li>Your application code does something like CacheFactory.getCache("my-cache-name");
                          <li>Using the cache mapping in the configuration the cache factory maps the cache name to the correct cache scheme in the configuration.
                          <li>Using the scheme configuration the cache factory will create the actual instance of the cache. If the cache is clustered (i.e. disributed, replicated, etc) then it will also be created on all the members of the cluster that are storage enabled for the service that the cache belongs to (the service name is also in the scheme configuration).
                          <li>In this case the cache scheme has a read write backing map, so when the cache is created on the storage enabled members this will also include creation of the cache store
                          <li>The cache store is created from the configuration in the cache scheme in the configuration file. Coherence will replace all of the system property and macro values in that configuration XML. So in this case the {cache-name} macro will be replaced with "my-cache-name".
                          <li>The cache factory will look up the relevant cache store class using the class name from the configuration.
                          <li>The cache factory will then try to find a constructor on that class that matches the init-param values in the configuration - in this case it will look for a constructor that takes a single String parameter (which will be the cache name).
                          <li>The cache factory will then call this constructor to create an instance of the cache store.
                          <li>If you use NJ's suggestion of using a factory then the factory method will be called instead of the constructor to create the cache store. In this case the factory method would need to have a single String parameter and it would return a Cache Store.

                          ...and that is about as much as you need at this point.

                          There isn;t much point in me describing what happens when you use a cache that has a cache store as this is all covered in the documentation here: http://docs.oracle.com/cd/E24290_01/coh.371/e22840/readthrough.htm#CHDBBJFC and here: http://docs.oracle.com/cd/E24290_01/coh.371/e22837/cache_rtwtwbra.htm#CFHEJHCI

                          Whether Coherence can improve performance of your application will depend on your specific use cases. I can see from this, and your other posts, that you have been looking at cache stores but again depending on your use case cache stores may not be the best option.

                          I have no idea what company you work for or where you are, but I can see you are new to Coherence. If there are other teams in your company using Coherence, then talk to them. Alternatively if you are the first and there is a real posibility that you will be buying licenses based on the success of your POC, then talk to Oracle about getting someone to come in for a day for some pre-sales presentaions/help.

                          Although the Coherence API is simple and you can get a cluster up and running very easily, Coherence is one of these tools that has a lot of ways of doing similar things and if you choose the wrong one it can be the difference between success and failure of your POC.

                          At least you are asking questions though, which is good. If you want more specific advice on particular use cases of your application then just post them as separate questions.

                          • 10. Re: Configure mutiple cache stores
                            Thanks JK for your patience and detailed explanation.

                            Yes.. as you said, Im very much new to Coherence and am the first to use in my org, hence require more detailed information on Coherence esp on how it works implementation wise.

                            Im working on the real-time application environment hence cache stores are required for my application as there are many applications running simultaneously with the same data and hence this cache store are required.
                            Ill sure take a point on the contacting pre-sales team after discussion with my management.

                            but mean while i still want to continue on my POC for Coherence and will be keep posting my queries..

                            Thanks JK and NJ for your valuable inputs.