[id='initializing-embedded-caches_{context}']
= Initializing embedded caches
Intialize the Cache Manager and add  embedded cache in your project to start running {brandname} in your application.

.Procedure

* Initialize the default Cache Manager and add an embedded cache named as follows:

[source,java,options="nowrap"]
----
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build());
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.DIST_SYNC);
cacheManager.administration().withFlags(CacheContainerAdmin.AdminFlag.VOLATILE).getOrCreateCache("myCache", builder.build());
----

The preceding code initializes a default, clustered Cache Manager.
Cache Managers contain your cache definitions and control cache lifecycles.

{brandname} does not provide a default cache configuration so after initializing
the default Cache Manager, you need to add at least one cache instance.
This example uses the `ConfigurationBuilder` class to create an embedded cache definition that uses the distributed, synchronous cache mode.
You then call the `getOrCreateCache()` method that either creates a cache named "myCache" on all nodes in the cluster or returns it if it already exists.

.Next steps

Now that you have a running Cache Manager with a cache created, you can add some more cache definitions, put some data into the cache, or configure {brandname} as needed.

[role="_additional-resources"]
.Additional resources
* link:{config_docs}#programmatic-configuring[Configuring {brandname} Programmatically]
* link:{javadocroot}/org/infinispan/configuration/global/GlobalConfigurationBuilder.html[org.infinispan.configuration.global.GlobalConfigurationBuilder]
* link:{javadocroot}/org/infinispan/manager/EmbeddedCacheManager.html[org.infinispan.manager.EmbeddedCacheManager]
* link:{javadocroot}/org/infinispan/Cache.html[org.infinispan.Cache]
