Search code examples
ignitein-memory-database

Apache Ignite difference between ignite.getOrCreateCache() vs ignite.cache()


I would like to clarify the differences between the following:

ignite.getOrCreateCache(cfg);

and

ignite.cache("cacheName")

The documentation on cache() says it

Gets an instance of IgniteCache API.

As for getOrCreateCache,

Gets existing cache with the given name or creates new one with the given configuration.

But they both return IgniteCache. Thank you!

https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/Ignite.html


Solution

  • With getOrCreateCache you can provide cache configuration that will be used to create new cache in case it doesn't exist yet. cache method will return null in this case.