Using ignite for local caching within a process

classic Classic list List threaded Threaded
4 messages Options
kohlisimranjit kohlisimranjit
Reply | Threaded
Open this post in threaded view
|

Using ignite for local caching within a process

This post has NOT been accepted by the mailing list yet.
Hi,
I want to use ignite for local caching with LRU. I want my code to initialize ignite via code
Ignite ignite = Ignition.start("./conf/example-cache.xml");
                cache = ignite.getOrCreateCache("cacheName");

But I think this starts the ignite server on a new JVM with separate heap. So I wanted to know is there anyway we can make ignite use the JVM and heap of the process which which starts it.  
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Using ignite for local caching within a process

kohlisimranjit wrote
Hi,
I want to use ignite for local caching with LRU. I want my code to initialize ignite via code
Ignite ignite = Ignition.start("./conf/example-cache.xml");
                cache = ignite.getOrCreateCache("cacheName");

But I think this starts the ignite server on a new JVM with separate heap. So I wanted to know is there anyway we can make ignite use the JVM and heap of the process which which starts it.
Hi,

Ignition.start() method never forks any external processes and starts the node in embedded mode within current JVM.

BTW, to enable LRU you can use LruEvictionPolicy which is provided out of the box. You can find a configuration example here: https://apacheignite.readme.io/docs/evictions#least-recently-used-lru

-Val
kohlisimranjit kohlisimranjit
Reply | Threaded
Open this post in threaded view
|

Re: Using ignite for local caching within a process

Interesting, the place where I am facing the issue is actually consider the case:
class SmallClass implements Serializable {
        int a;
        int b;
}

class BigClass implements Serializable{
        SmallClass smallClass1 = new SmallClass();
        SmallClass smallClass2 = new SmallClass();
}

And lets say if execute the following steps:
Ignite ignite = Ignition.start("./conf/example-cache.xml");
IgniteCache<String, Object> cache  = ignite.getOrCreateCache("cacheName");

BigClass bigClass = new BigClass();
getCache().put("a",bigClass);
bigClass.smallClass1.a=10;
bigClass=(BigClass)(getCache().get("a"));
System.out.println("bigClass value-> "+bigClass.smallClass1.a);  

Answer:
bigClass value-> 0
Since its using local heap expected is
bigClass value-> 10

But it appears that since an object is cached any changes to it using the reference with which it was cached aren't reflected. I guess thats how caching works in ignite.




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

Re: Using ignite for local caching within a process

Yes, this is how it works. To ensure data consistency, cache always makes the copy of the object before saving it, so you should always use cache operations (put, remove, etc.) to update it.

Makes sense?

-Val