Can I use the JCache API for distributed caches in Apache Ignite?

classic Classic list List threaded Threaded
3 messages Options
Henrik Lundahl Henrik Lundahl
Reply | Threaded
Open this post in threaded view
|

Can I use the JCache API for distributed caches in Apache Ignite?

Hi

I would like to configure a distributed cache with Apache Ignite using the JCache API (JSR107, javax.cache). Is this possible?

The examples I have found either create a local cache with the JCache API or create a distributed cache (or datagrid) using the Apache Ignite API.

Here is the same question on Stack Overflow.


BR

--
Henrik

vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Can I use the JCache API for distributed caches in Apache Ignite?

Hi Henrik,

JCache allows to provide provider-specific configuration when creating a cache. I.e., you can do this:

    // Get or create a cache manager.
    CacheManager cacheMgr = Caching.getCachingProvider().getCacheManager();
   
    // This is an Ignite configuration object (org.apache.ignite.configuration.CacheConfiguration).
    CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
   
    // Specify cache mode and/or any other Ignite-specific configuration properties.
    cfg.setCacheMode(CacheMode.PARTITIONED);
   
    // Create a cache based on configuration create above.
    Cache<Integer, String> cache = cacheMgr.createCache("a", cfg);

Also note that partitioned mode is actually the default one in Ignite, so you are not required to specify it explicitly.

-Val
Henrik Lundahl Henrik Lundahl
Reply | Threaded
Open this post in threaded view
|

Re: Can I use the JCache API for distributed caches in Apache Ignite?

Hi

Got it working by providing a config file to the getCacheManager method as you suggested on SO. Thanks!


--
Henrik



On Tue, Jan 26, 2016 at 11:27 PM, vkulichenko <[hidden email]> wrote:
Hi Henrik,

JCache allows to provide provider-specific configuration when creating a
cache. I.e., you can do this:

    // Get or create a cache manager.
    CacheManager cacheMgr = Caching.getCachingProvider().getCacheManager();

    // This is an Ignite configuration object
(org.apache.ignite.configuration.CacheConfiguration).
    CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();

    // Specify cache mode and/or any other Ignite-specific configuration
properties.
    cfg.setCacheMode(CacheMode.PARTITIONED);

    // Create a cache based on configuration create above.
    Cache<Integer, String> cache = cacheMgr.createCache("a", cfg);

Also note that partitioned mode is actually the default one in Ignite, so
you are not required to specify it explicitly.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Can-I-use-the-JCache-API-for-distributed-caches-in-Apache-Ignite-tp2726p2731.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.