<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2019 Red Hat, Inc. and/or its affiliates
  ~ and other contributors as indicated by the @author tags.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<infinispan
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:infinispan:config:11.0 http://www.infinispan.org/schemas/infinispan-config-11.0.xsd"
        xmlns="urn:infinispan:config:11.0">

{% if keycloak_jgroups_extended_stack %}
    <!-- custom stack goes into the jgroups element -->
    <jgroups>
        <stack name="{{ keycloak_jgroups_extended_stack_name }}" extends="{{ keycloak_cache_stack }}">
            <UDP bind_addr="${jgroups.bind.address,jgroups.udp.address:SITE_LOCAL}"
                bind_port="{{ keycloak_jgroups_bind_port }}"
                mcast_addr="{{ keycloak_jgroups_multicast_address }}"
                mcast_port="{{ keycloak_jgroups_multicast_port }}"
                tos="0"
                ucast_send_buf_size="1m"
                mcast_send_buf_size="1m"
                ucast_recv_buf_size="20m"
                mcast_recv_buf_size="25m"
                ip_ttl="${jgroups.ip_ttl:2}"
                thread_naming_pattern="pl"
                enable_diagnostics="false"
                bundler_type="transfer-queue"
                max_bundle_size="8500"

                thread_pool.min_threads="${jgroups.thread_pool.min_threads:0}"
                thread_pool.max_threads="${jgroups.thread_pool.max_threads:200}"
                thread_pool.keep_alive_time="60000"

                thread_dumps_threshold="${jgroups.thread_dumps_threshold:10000}" />
        </stack>
    </jgroups>
{% endif %}
    <cache-container name="keycloak">
        <transport cluster="{{ keycloak_cache_container_name }}"{% if keycloak_jgroups_extended_stack %}   stack="{{ keycloak_jgroups_extended_stack_name }}"{% endif %} node-name="{{ keycloak_jgroups_cache_hostname }}" lock-timeout="60000"/>
        <local-cache name="realms">
            <encoding>
                <key media-type="application/x-java-object"/>
                <value media-type="application/x-java-object"/>
            </encoding>
            <memory max-count="10000"/>
        </local-cache>
        <local-cache name="users">
            <encoding>
                <key media-type="application/x-java-object"/>
                <value media-type="application/x-java-object"/>
            </encoding>
            <memory max-count="10000"/>
        </local-cache>
        <distributed-cache name="sessions" owners="2">
            <expiration lifespan="-1"/>
        </distributed-cache>
        <distributed-cache name="authenticationSessions" owners="2">
            <expiration lifespan="-1"/>
        </distributed-cache>
        <distributed-cache name="offlineSessions" owners="2">
            <expiration lifespan="-1"/>
        </distributed-cache>
        <distributed-cache name="clientSessions" owners="2">
            <expiration lifespan="-1"/>
        </distributed-cache>
        <distributed-cache name="offlineClientSessions" owners="2">
            <expiration lifespan="-1"/>
        </distributed-cache>
        <distributed-cache name="loginFailures" owners="2">
            <expiration lifespan="-1"/>
        </distributed-cache>
        <local-cache name="authorization">
            <encoding>
                <key media-type="application/x-java-object"/>
                <value media-type="application/x-java-object"/>
            </encoding>
            <memory max-count="10000"/>
        </local-cache>
        <replicated-cache name="work">
            <expiration lifespan="-1"/>
        </replicated-cache>
        <local-cache name="keys">
            <encoding>
                <key media-type="application/x-java-object"/>
                <value media-type="application/x-java-object"/>
            </encoding>
            <expiration max-idle="3600000"/>
            <memory max-count="1000"/>
        </local-cache>
        <distributed-cache name="actionTokens" owners="2">
            <encoding>
                <key media-type="application/x-java-object"/>
                <value media-type="application/x-java-object"/>
            </encoding>
            <expiration max-idle="-1" lifespan="-1" interval="300000"/>
            <memory max-count="-1"/>
        </distributed-cache>
    </cache-container>
</infinispan>