ignite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Markus Wiesenbacher" <mailingl...@codefreun.de>
Subject AW: Programmatic default definition for a Cache
Date Fri, 20 Feb 2015 12:38:21 GMT
Hi Dmitriy,

thanks for you answer. I know about this principle, but therefore I would need to know all
caches at starting-time. At runtime I need plenty of different caches/maps and I thought it
would be possible to have one configuration and can instantiate numerous caches from it (1:n).
Now it´s one configuration for one cache (1:1).

But that´s only an administrative problem, I can live with that, putting some unique keys
in with the payload as object.

Thanks!
Markus

-----Ursprüngliche Nachricht-----
Von: Dmitriy Setrakyan [mailto:dsetrakyan@apache.org] 
Gesendet: Freitag, 20. Februar 2015 11:01
An: dev@ignite.incubator.apache.org
Cc: mailinglist@codefreun.de
Betreff: Re: Programmatic default definition for a Cache

Hi Markus,

Thanks for your interest in Ignite.

If you need to define 2 different caches, you should add them separately to IgniteConfiguration
and give them different names, like so:

----
CacheConfiguration<String, String> cacheConfig1 = new CacheConfiguration<String,
String>();

cacheConfig.setName("CACHE1");
cacheConfig.setCacheMode(CacheMode.REPLICATED);
cacheConfig.setDistributionMode(CacheDistributionMode.PARTITIONED_ONLY);

// Create another configuration based on the 1st one.
CacheConfiguration<String, String> cacheConfig2 = new CacheConfiguration(cacheConfgi1);

cacheConfig2.setName("CACHE2");

IgniteConfiguration config = new IgniteConfiguration();

config.setCacheConfiguration(cacheConfig1, cacheConfig2);
----

Then in your code further you can access cache1 and cache2 by name, like so:

----
*IgniteCache cache1 = ignite.jcache("CACHE1");* *IgniteCache cache2 = ignite.jcache("CACHE2");*
----

Please feel free to send more questions as they come. You can also utilize the Support space
here:
http://apacheignite.readme.io/v1.0/discuss

D.

On Thu, Feb 19, 2015 at 11:27 PM, Markus Wiesenbacher < mailinglist@codefreun.de> wrote:

> Hi,
>
>
>
> I am currently switching from Hazelcast to GridGain / Ignite and want 
> to use more than one IgniteCache-instance of the same Configuration. 
> If I am using
> Ignite.jcache(String) I need to name a CacheConfiguration, which 
> always delivers the same instance if used with Ingite.jcache(String).
>
>
>
> Is there a way to get always a new instance or define a 
> default-configuration? Now I am getting an error if I want to get an 
> instance without same named Configuration.
>
>
>
> Here my test-code:
>
>
>
> package com.peertank.driver.ignite;
>
>
>
> import java.util.UUID;
>
>
>
> import org.apache.ignite.Ignite;
>
> import org.apache.ignite.IgniteCache;
>
> import org.apache.ignite.Ignition;
>
> import org.apache.ignite.cache.CacheDistributionMode;
>
> import org.apache.ignite.cache.CacheMode;
>
> import org.apache.ignite.configuration.CacheConfiguration;
>
> import org.apache.ignite.configuration.IgniteConfiguration;
>
>
>
> public class IgniteTest {
>
>
>
>        public static void main (String[] args) {
>
>
>
>              CacheConfiguration<String, String> cacheConfig = new 
> CacheConfiguration<String, String>();
>
>              cacheConfig.setName
> ("CACHE_PARTITIONED_OFFHEAP");
>
>              cacheConfig.setCacheMode
> (CacheMode.REPLICATED);
>
>              cacheConfig.setDistributionMode 
> (CacheDistributionMode.PARTITIONED_ONLY);
>
>
>
>              IgniteConfiguration config        = new IgniteConfiguration();
>
>              config.setCacheConfiguration      (cacheConfig);
>
>              config.setNodeId                        (UUID.randomUUID());
>
>              config.setGridName                      ("THEGRID");
>
>
>
>              Ignite ignite = Ignition.start (config);
>
>
>
>
>
>              // === Cache 1
>
>
>
>              IgniteCache<String, String> cache = ignite.jcache 
> ("CACHE_PARTITIONED_OFFHEAP");
>
>
>
>              cache.put ("name", "foo");
>
>
>
>              // === Cache 2
>
>
>
>              IgniteCache<String, String> cache2 = ignite.jcache 
> ("CACHE_PARTITIONED_OFFHEAP");
>
>
>
>              cache2.put ("name", "bar");
>
>
>
>              // === Output
>
>
>
>              System.out.println (cache.get ("name"));       // expected
> "foo" but delivers "bar"
>
>              System.out.println (cache2.get ("name"));             //
> expected "bar"
>
>        }
>
> }
>
>
>
>
>
> Best regards
>
> Markus
>
>


Mime
View raw message