Ignite - Manually trigger persistence

Viewed 51

I have an application using in-memory ignite caches. What I would like to do is, after user input, trigger the persistence of those caches in a Postgres DB.

I already checked the ignite persistence with writeThrough and WriteBehindEnabled properties. it doesn't work in this case because I don't want to write on the db every time I write on the caches.

I also found that, when configuring the caches with persistence, we create the store with a CacheConfiguration<key, value>, we can then use the following to trigger a write :

cache.getSnap(ignite, snapdId).getCache().forEach(e -> {
            cache.getConfig().getCacheStoreFactory().create().write(e);
        });

Unfortunately this throws an exception with this.session().cacheName() as the session is null. The this.session() returns the following attribute: @CacheStoreSessionResource private CacheStoreSession ses;

If someone knows how I could do that, that would very much help me.

Thanks !

1 Answers

That's just not how the Cache Store is intended to work. I would suggest either:

  1. Two tables, one writes through to Postgres, the other one is purely in-memory. In this one, you can use the JDBC Cache Store adapter
  2. Write your own Cache Store adapter. In this, you would have an extra column that would indicate whether the row should be written through
Related