[id='run_library']
= Running {brandname} as an Embedded Library
Learn how to run {brandname} as an embedded data store in your project.

.Procedure

* Initialize the default Cache Manager and add a cache definition 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 default cache definitions so after initializing
the default Cache Manager, you need to add at least one cache instance. This
example uses the `ConfigurationBuilder` class to create a 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.

.Reference

* 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]
