이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 16. Creating caches with Data Grid Operator


Use Cache CRs to add cache configuration with Data Grid Operator and control how Data Grid stores your data.

16.1. Data Grid caches

Cache configuration defines the characteristics and features of the data store and must be valid with the Data Grid schema. Data Grid recommends creating standalone files in XML or JSON format that define your cache configuration. You should separate Data Grid configuration from application code for easier validation and to avoid the situation where you need to maintain XML snippets in Java or some other client language.

To create caches with Data Grid clusters running on OpenShift, you should:

  • Use Cache CR as the mechanism for creating caches through the OpenShift front end.
  • Use Batch CR to create multiple caches at a time from standalone configuration files.
  • Access Data Grid Console and create caches in XML or JSON format.

You can use Hot Rod or HTTP clients but Data Grid recommends Cache CR or Batch CR unless your specific use case requires programmatic remote cache creation.

Cache CRs

  • Cache CRs apply to Data Grid service pods only.
  • Each Cache CR corresponds to a single cache on the Data Grid cluster.

16.2. Creating caches with the Cache CR

Complete the following steps to create caches on Data Grid service clusters using valid configuration in XML or YAML format.

Procedure

  1. Create a Cache CR with a unique value in the metadata.name field.
  2. Specify the target Data Grid cluster with the spec.clusterName field.
  3. Name your cache with the spec.name field.

    Note

    The name attribute in the cache configuration does not take effect. If you do not specify a name with the spec.name field then the cache uses the value of the metadata.name field.

  4. Add a cache configuration with the spec.template field.
  5. Apply the Cache CR, for example:

    oc apply -f mycache.yaml
    cache.infinispan.org/mycachedefinition created
    Copy to Clipboard Toggle word wrap

Cache CR examples

XML

apiVersion: infinispan.org/v2alpha1
kind: Cache
metadata:
  name: mycachedefinition
spec:
  clusterName: infinispan
  name: myXMLcache
  template: <distributed-cache mode="SYNC" statistics="true"><encoding media-type="application/x-protostream"/><persistence><file-store/></persistence></distributed-cache>
Copy to Clipboard Toggle word wrap

YAML

apiVersion: infinispan.org/v2alpha1
kind: Cache
metadata:
  name: mycachedefinition
spec:
  clusterName: infinispan
  name: myYAMLcache
  template: |-
    distributedCache:
      mode: "SYNC"
      owners: "2"
      statistics: "true"
      encoding:
        mediaType: "application/x-protostream"
      persistence:
        fileStore: ~
Copy to Clipboard Toggle word wrap

16.3. Updating caches with the Cache CR

You can control how Data Grid Operator handles modifications to the cache configuration in the Cache CR.

Data Grid Operator attempts to update the cache configuration on the Data Grid Server at runtime. If the update fails, Data Grid Operator uses one of the following strategies:

retain strategy
The Operator updates the status of the Cache CR to Ready=False. You can manually delete the Cache CR and create a new cache configuration. This is the default strategy.
recreate strategy

The Operator deletes the cache from the Data Grid cluster and creates a new cache with the latest spec.template value from the Cache CR.

Important

Configure the recreate strategy only if your deployment can tolerate data loss.

Prerequisites

  • Have a valid Cache CR.

Procedure

  1. Use the spec.updates.strategy field to set the Cache CR strategy.

    mycache.yaml

    spec:
      updates:
        strategy: recreate
    Copy to Clipboard Toggle word wrap

  2. Apply changes to the Cache CR, for example:

    oc apply -f mycache.yaml
    Copy to Clipboard Toggle word wrap

16.4. Adding persistent cache stores

You can add persistent cache stores to Data Grid service pods to save data to the persistent volume.

Data Grid creates a Single File cache store, .dat file, in the /opt/infinispan/server/data directory.

Procedure

  • Add the <file-store/> element to the persistence configuration in your Data Grid cache, as in the following example:

    <distributed-cache name="persistent-cache" mode="SYNC">
      <encoding media-type="application/x-protostream"/>
      <persistence>
        <file-store/>
      </persistence>
    </distributed-cache>
    Copy to Clipboard Toggle word wrap

16.5. Adding caches to Cache service pods

Cache service pods include a default cache configuration with recommended settings. This default cache lets you start using Data Grid without the need to create caches.

Note

Because the default cache provides recommended settings, you should create caches only as copies of the default. If you want multiple custom caches you should create Data Grid service pods instead of Cache service pods.

Procedure

  • Access the Data Grid Console and provide a copy of the default configuration in XML or JSON format.
  • Use the Data Grid CLI to create a copy from the default cache as follows:

    [//containers/default]> create cache --template=default mycache
    Copy to Clipboard Toggle word wrap

16.5.1. Default cache configuration

This topic describes default cache configuration for Cache service pods.

<distributed-cache name="default"
                   mode="SYNC"
                   owners="2">
  <memory storage="OFF_HEAP"
          max-size="<maximum_size_in_bytes>"
          when-full="REMOVE" />
  <partition-handling when-split="ALLOW_READ_WRITES"
                      merge-policy="REMOVE_ALL"/>
</distributed-cache>
Copy to Clipboard Toggle word wrap

Default caches:

  • Use synchronous distribution to store data across the cluster.
  • Create two replicas of each entry on the cluster.
  • Store cache entries as bytes in native memory (off-heap).
  • Define the maximum size for the data container in bytes. Data Grid Operator calculates the maximum size when it creates pods.
  • Evict cache entries to control the size of the data container. You can enable automatic scaling so that Data Grid Operator adds pods when memory usage increases instead of removing entries.
  • Use a conflict resolution strategy that allows read and write operations for cache entries, even if segment owners are in different partitions.
  • Specify a merge policy that removes entries from the cache when Data Grid detects conflicts.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat