rbakhru
rbakhru

Reputation: 61

Add cache at runtime to GridGain / reconfigure GridGain at runtime

Is there a means of reconfiguring the GridCacheConfiguration at runtime for GridGain?

The end goal is to be able to add a grid cache at runtime after having started up the Grid.

final GridConfiguration gridConfiguration = new GridConfiguration();
gridConfiguration.setMarshaller(new GridOptimizedMarshaller());
Grid grid = GridGain.start(gridConfiguration);
...

<later on>
GridCacheConfiguration newCacheConfig = ...; //defines newConfig
grid.configuration().setCacheConfiguration(newCacheConfig);

grid.cache("newConfig"); // <-- throws a cache not defined error!

Upvotes: 1

Views: 140

Answers (1)

Dmitriy
Dmitriy

Reputation: 2292

Adding caches usually has to do with handling different data types (generics), which GridGain addresses with GridCacheProjections, like so:

GridCacheProjection<Integer, MyType> prj = cache.projection(Integer.class, MyType.class);

You can create as many different projection from the same cache as needed. In addition to specifying data types, you can also use projections to turn cache flags on and off, or to provide filtered view for the cache with projection filters.

Upvotes: 1

Related Questions