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 <
[email protected]> 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
>
>