19 Using Cache Configuration Override

Coherence 14.1.1.2206 introduces the cache configuration override, a feature similar to the Coherence Cluster override. You can specify the cache configuration override by using the xml-override attribute in the root element of cache configuration. The root element is referred to as the "base" cache configuration file whose elements you can now override by placing the override file in the classpath or a module path. If the specified XML override file is found on the classpath or a module path, Coherence loads the file at runtime and overrides the base configuration based on each module’s specific requirements.

This chapter includes the following topics:

Specifying the xml-override Attribute

Based on the xml-override attribute you specify, Coherence loads the cache-config-override.xml file and applies when it is found on the classpath or a module path of the application when you do not specify the coherence.cacheconfig.override system property. If you specify coherence.cacheconfig.override, Coherence loads the XML override pointed by this system property and applies it at runtime.
The following is a snippet of the cache config XML file with the xml-override attribute specified:
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
              xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd"
              xml-override="{coherence.cacheconfig.override cache-config-override.xml}">
    ....
</cache-config>

Use Cases for Overriding Coherence Cache Configuration

The use cases in this section describe the different scenarios for overriding Coherence cache configuration.

  • Cache configuration override has caching-scheme-mapping/cache-mapping that already exists in the base cache configuration with the same cache-name

    In this case, the cache-mapping element within caching-scheme-mapping is overridden from the override file, as shown in the following example:

    • Base XML
      <cache-mapping>
          <cache-name>my-cache-*</cache-name>
          <scheme-name>my-cache-scheme-parent</scheme-name>
      </cache-mapping>
    • Override XML
      <cache-mapping>
          <cache-name>my-cache-*</cache-name>
          <scheme-name>my-cache-scheme-override</scheme-name>
      </cache-mapping>
    • The effective <caching-scheme-mapping> element after the application of the XML override to the base XML
      <caching-scheme-mapping>
          <cache-mapping>
              <cache-name>my-cache-*</cache-name>
              <scheme-name>my-cache-scheme-override</scheme-name>
          </cache-mapping>
      </caching-scheme-mapping>
  • Cache configuration override has caching-scheme-mapping/cache-mapping that does not exist in the base cache configuration

    In this case, the new <cache-mapping> element from the override file prepends to the other elements within caching-scheme-mapping, as shown in the following example:

    • Base XML
      <cache-mapping>
          <cache-name>my-cache-*</cache-name>
          <scheme-name>my-cache-scheme-parent</scheme-name>
      </cache-mapping>
    • Override XML
      <cache-mapping>
          <cache-name>my-cache-override</cache-name>
          <scheme-name>my-cache-scheme-override</scheme-name>
      </cache-mapping>
    • The effective <caching-scheme-mapping> element after the application of the XML override to the base XML
      <caching-scheme-mapping>
          <cache-mapping>
              <cache-name>my-cache-override</cache-name>
              <scheme-name>my-cache-scheme-override</scheme-name>
          </cache-mapping>
          <cache-mapping>
              <cache-name>my-cache-*</cache-name>
              <scheme-name>my-cache-scheme-parent</scheme-name>  
          </cache-mapping>
      </caching-scheme-mapping>
  • Cache configuration override has caching-scheme with the same scheme-name that exists in the base configuration file

    Only a caching-scheme with the given scheme-name is merged with the relevant content from the override file, as shown in the following example:

    • Base XML
      <caching-schemes>
         <distributed-scheme>
            <scheme-name>my-cache-scheme</scheme-name>
            <service-name>MyCache</service-name>
            <backing-map-scheme>
               <local-scheme>
                  <unit-calculator>BINARY</unit-calculator>
               </local-scheme>
            </backing-map-scheme>
            <partitioned-quorum-policy-scheme>
               <write-quorum>3</write-quorum>
            </partitioned-quorum-policy-scheme>
            <autostart>true</autostart>
         </distributed-scheme>
         <distributed-scheme>
            <scheme-name>my-cache-scheme-two</scheme-name>
            <service-name>MyCache2</service-name>
         </distributed-scheme>
      <caching-schemes>
    • Override XML
      <caching-schemes>
          <distributed-scheme>
            <scheme-name>my-cache-scheme</scheme-name>
            <partitioned-quorum-policy-scheme>
               <write-quorum>1</write-quorum>
            </partitioned-quorum-policy-scheme>
          </distributed-scheme>
      </caching-schemes>
    • The effective <caching-schemes> element after the application of the XML override
      <caching-schemes>
         <distributed-scheme>
            <scheme-name>my-cache-scheme</scheme-name>
            <service-name>MyCache</service-name>
            <backing-map-scheme>
               <local-scheme>
                  <unit-calculator>BINARY</unit-calculator>
               </local-scheme>
            </backing-map-scheme>
            <partitioned-quorum-policy-scheme>
               <write-quorum>1</write-quorum>
            </partitioned-quorum-policy-scheme>
            <autostart>true</autostart>
         </distributed-scheme>
         <distributed-scheme>
            <scheme-name>my-cache-scheme-two</scheme-name>
            <service-name>MyCache2</service-name>
         </distributed-scheme>
      <caching-schemes>
  • Cache configuration override with caching-schemes without any scheme-name

    All types of that caching-scheme is modified with the relevant content from the override file, as shown in the following example:

    • Base XML
      <caching-schemes>
         <distributed-scheme>
            <scheme-name>my-cache-scheme</scheme-name>
            <service-name>MyCache</service-name>
            <backing-map-scheme>
               <local-scheme>
                  <unit-calculator>BINARY</unit-calculator>
               </local-scheme>
            </backing-map-scheme>
            <partitioned-quorum-policy-scheme>
               <write-quorum>3</write-quorum>
            </partitioned-quorum-policy-scheme>
            <autostart>true</autostart>
         </distributed-scheme>
         <distributed-scheme>
            <scheme-name>my-cache-scheme-two</scheme-name>
            <service-name>MyCache2</service-name>
         </distributed-scheme>
      <caching-schemes>
    • Override XML
      <caching-schemes>
         <distributed-scheme>
            <partitioned-quorum-policy-scheme>
               <write-quorum>1</write-quorum>
            </partitioned-quorum-policy-scheme>
         </distributed-scheme>
      </caching-schemes>
    • The effective <caching-schemes> element after the application of the XML override
      <caching-schemes>
         <distributed-scheme>
            <scheme-name>my-cache-scheme</scheme-name>
            <service-name>MyCache</service-name>
            <backing-map-scheme>
               <local-scheme>
                  <unit-calculator>BINARY</unit-calculator>
               </local-scheme>
            </backing-map-scheme>
            <partitioned-quorum-policy-scheme>
               <write-quorum>1</write-quorum>
            </partitioned-quorum-policy-scheme>
            <autostart>true</autostart>
         </distributed-scheme>
         <distributed-scheme>
            <scheme-name>my-cache-scheme-two</scheme-name>
            <service-name>MyCache2</service-name>
            <partitioned-quorum-policy-scheme>
               <write-quorum>1</write-quorum>
            </partitioned-quorum-policy-scheme>
         </distributed-scheme>
      <caching-schemes>