Este conteúdo não está disponível no idioma selecionado.

Chapter 7. Remotely Creating Caches


When you remotely create caches with the cache-service, you can configure caches to be ephemeral or permanent and if data is replicated across the cluster.

You can define any custom configuration when you remotely create caches with the datagrid-service.

Remotely create cache definitions with the cache-service and datagrid-service through the Hot Rod protocol as follows:

  1. Instantiate the RemoteCacheManager class to connect to the service.
  2. Call the createCache() method to create a cache, as in the following example:

    private static void createCache(String appName) {
          //Connect to the Hot Rod service.
          final String host = appName;
          //Use the configuration bean.
          ConfigurationBuilder cfg = ...
    
          System.out.printf("--- Connecting to %s ---%n", appName);
    
          //Create a new RemoteCacheManager and start it.
          final RemoteCacheManager remote = new RemoteCacheManager(cfg.build());
    
          //Set a name for the cache.
          final String cacheName = "custom";
    
          System.out.printf("--- Creating cache in %s ---%n", appName);
    
          //Perform remote administration operations.
          remote.administration()
             //Include a flag to make the cache permanent.
             .withFlags(CacheContainerAdmin.AdminFlag.PERMANENT)
             //Create a cache on the remote server.
             //Pass null instead of XML to use the default cache configuration.
             .createCache(cacheName, null);
    
          System.out.printf("--- Cache '%s' created in '%s' ---%n", cacheName, appName);
    }
    Copy to Clipboard Toggle word wrap
    Note

    If the named cache already exists, an exception is thrown. Alternatives are to:

    • Call the getOrCreateCache method in RemoteCacheManagerAdmin to return the cache name instead of throwing an exception.
    • Call the removeCache method in RemoteCacheManagerAdmin to destroy the cache and then call createCache again.
Tip
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat