Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 4. Configuring Data Grid Caches
Data Grid lets you define properties and options for caches both declaratively and programmatically.
Declarative configuration uses XML files that adhere to a Data Grid schema. Programmatic configuration, on the other hand, uses Data Grid APIs.
In most cases, you use declarative configuration as a starting point for cache definitions. At runtime you can then programmatically configure your caches to tune settings or specify additional properties. However, Data Grid provides flexibility so you can choose either declarative, programmatic, or a combination of the two.
4.1. Declarative Configuration Link kopierenLink in die Zwischenablage kopiert!
Declarative configuration conforms to a schema and is defined in XML or JSON formatted files.
The following example shows the basic structure of a Data Grid configuration:
4.1.1. Cache Templates Link kopierenLink in die Zwischenablage kopiert!
Data Grid lets you define templates that you can use to create cache configurations.
For example, the following configuration contains a cache template:
Inheritance with configuration templates
Configuration templates can also inherit from other templates to extend and override settings.
Cache template inheritance is hierarchical. For a child configuration template to inherit from a parent, you must include it after the parent template.
The following is an example of template inheritance:
Configuration template inheritance is additive for elements that have multiple values, such as property
. Resulting child configurations merge values from parent configurations.
For example, <property value_x="foo" />
in a parent configuration merges with <property value_y="bar" />
in a child configuration to result in <property value_x="foo" value_y="bar" />
.
4.1.2. Cache Configuration Wildcards Link kopierenLink in die Zwischenablage kopiert!
You can use wildcards to match cache definitions to configuration templates.
Data Grid throws exceptions if cache names match more than one wildcard.
4.1.3. Multiple Configuration Files Link kopierenLink in die Zwischenablage kopiert!
Data Grid supports XML inclusions (XInclude) that allow you to split configuration across multiple files.
If you want to use a schema for your included fragments, use the infinispan-config-fragment-12.1.xsd
schema:
<local-cache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:12.1 https://infinispan.org/schemas/infinispan-config-fragment-12.1.xsd" xmlns="urn:infinispan:config:12.1" name="mycache"/>
<local-cache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:12.1 https://infinispan.org/schemas/infinispan-config-fragment-12.1.xsd"
xmlns="urn:infinispan:config:12.1"
name="mycache"/>
Data Grid configuration provides only minimal support for the XInclude specification. For example, you cannot use the xpointer
attribute, the xi:fallback
element, text processing, or content negotiation.
Reference
4.2. Data Grid Configuration API Link kopierenLink in die Zwischenablage kopiert!
Configure Data Grid programmatically.
Global configuration
Use the GlobalConfiguration
class to apply configuration to all caches under the Cache Manager.
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .cacheContainer().statistics(true) .metrics().gauges(true).histograms(true) .jmx().enable() .build();
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
.cacheContainer().statistics(true)
.metrics().gauges(true).histograms(true)
.jmx().enable()
.build();
References:
Cache configuration
Use the ConfigurationBuilder
class to configure caches.
References:
4.3. Configuring Caches Programmatically Link kopierenLink in die Zwischenablage kopiert!
Define cache configurations with the Cache Manager.
The examples in this section use EmbeddedCacheManager
, which is a Cache Manager that runs in the same JVM as the client.
To configure caches remotely with HotRod clients, you use RemoteCacheManager
. Refer to the HotRod documentation for more information.
Configure new cache instances
The following example configures a new cache instance:
Create new caches from existing configurations
The following examples create new cache configurations from existing ones:
- 1
- Returns the default cache configuration from the Cache Manager. In this example,
infinispan-prod.xml
defines a replicated cache as the default. - 2
- Creates a new Configuration object that uses the default cache configuration as a base.
- 3
- Specifies distributed, synchronous cache mode.
- 4
- Adds an L1 lifespan configuration.
- 5
- Defines a new cache named "distributedWithL1" with the Configuration object.
- 1
- Uses a cache configuration named "replicatedCache" as a base.