[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 caches configuration templates or {brandname}
cache definitions in XML format.

.Programmatic procedure

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

ConfigurationBuilder builder = new ConfigurationBuilder();
builder
  .remoteCache("my-cache")
    .templateName("org.infinispan.DIST_SYNC") <1>
  .remoteCache("another-cache")
    .configuration("<infinispan><cache-container><distributed-cache name=\"another-cache\"/></cache-container></infinispan>"); <2>
----

<1> Creates a cache named `my-cache` that uses the `org.infinispan.DIST_SYNC` template.
<2> Creates a cache named `another-cache` that uses the specified XML definition.

.Hot Rod client properties

[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>
----

<1> Creates a cache named `my-cache` that uses the `org.infinispan.DIST_SYNC` template.
<2> Creates a cache named `another-cache` that uses the specified XML definition.
