[id='hotrod_create_caches_on_access']
= Creating Caches on First Access
When Hot Rod Java clients attempt to access caches that do not exist, they
return `null` for `getCache("$cacheName")` invocations.

You can change this default behavior so that clients automatically create
caches on first access using default configuration templates or {brandname}
cache definitions in XML format.

.Programmatic procedure

* Use the `remoteCache()` method to create per-cache configurations in the Hot Rod `ConfigurationBuilder` class as follows:

[source,java,options="nowrap"]
----
import org.infinispan.client.hotrod.DefaultTemplate;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
...

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.remoteCache("my-cache") <1>
    .templateName(DefaultTemplate.DIST_SYNC)
builder.remoteCache("another-cache") <2>
    .configuration("<infinispan><cache-container><distributed-cache name=\"another-cache\"/></cache-container></infinispan>");
builder.remoteCache("my-other-cache") <3>
    .configurationURI(URI.create("file:/path/to/configuration.xml"));
----

<1> Creates a cache named "my-cache" from the `org.infinispan.DIST_SYNC` template.
<2> Creates a cache named "another-cache" from an XML definition.
<3> Creates a cache named "my-other-cache" from an XML file.


.Hot Rod client properties

* Add `infinispan.client.hotrod.cache.<cache-name>` properties to your `hotrod-client.properties` file to create per-cache configurations as follows:

[source,options="nowrap"]
----
infinispan.client.hotrod.cache.my-cache.template_name=org.infinispan.DIST_SYNC <1>
infinispan.client.hotrod.cache.another-cache.configuration=<infinispan><cache-container><distributed-cache name=\"another-cache\"/></cache-container></infinispan> <2>
infinispan.client.hotrod.cache.my-other-cache.configuration_uri=file:/path/to/configuration.xml <3>
----

<1> Creates a cache named "my-cache" from the `org.infinispan.DIST_SYNC` template.
<2> Creates a cache named "another-cache" from an XML definition.
<3> Creates a cache named "my-other-cache" from an XML file.

.Reference

* link:{javadocroot}/org/infinispan/client/hotrod/configuration/package-summary.html[Hot Rod Client Configuration]
* link:{javadocroot}/org/infinispan/client/hotrod/configuration/RemoteCacheConfigurationBuilder.html[org.infinispan.client.hotrod.configuration.RemoteCacheConfigurationBuilder]
* link:{javadocroot}/org/infinispan/client/hotrod/DefaultTemplate.html[org.infinispan.client.hotrod.DefaultTemplate]
