<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:cache="http://www.springframework.org/schema/cache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
     http://www.springframework.org/schema/cache
     http://www.springframework.org/schema/cache/spring-cache.xsd
    ">
    <!--<context:property-placeholder location="classpath:cacheCloudClient.properties"/>-->
    <context:component-scan base-package="service">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!-- 默认生成的缓存key的实现策略 -->
    <bean id="defaultCacheKeyGenerator" class="com.elab.cache.spring.generator.DefaultCacheKeyGenerator">
        <property name="prefix" value="demo"/>
        <property name="separator" value="_"/>
    </bean>

    <!--<bean id="namedCacheResolver" class="org.springframework.cache.interceptor.NamedCacheResolver">-->
    <!--<property name="cacheNames">-->
    <!--<list>-->
    <!--<value>redisClient</value>-->
    <!--</list>-->
    <!--</property>-->
    <!--<property name="cacheManager" ref="cacheManager" />-->
    <!--</bean>-->

    <!-- 异常处理类 -->
    <bean id="errorCacheHandle" class="com.elab.cache.spring.handle.ErrorCacheHandle"/>

    <!-- 开启缓存扫描注解包 -->
    <cache:annotation-driven error-handler="errorCacheHandle" key-generator="defaultCacheKeyGenerator"/>

    <!-- 客户端操作类 -->
    <!--<bean id="redisClusterClient" class="com.elab.cache.redis.RedisClusterClient" init-method="init" lazy-init="true">-->
    <!--<property name="redisBuilder" ref="redisClusterBuilder"></property>-->
    <!--</bean>-->

    <!-- 主备 -->
    <bean id="redisSentineClient" class="com.elab.cache.redis.RedisSentinelClient" init-method="init" lazy-init="true">
        <property name="redisBuilder" ref="redisSentinelBuilder"/>
        <property name="password" value="elab@123"/>
    </bean>

    <!-- 单机 -->
    <bean id="redisStandaloneClient" class="com.elab.cache.redis.RedisStandaloneClient" init-method="init"
          lazy-init="true">
        <property name="redisBuilder" ref="redisStandaloneBuilder"/>
        <property name="password" value="elab@123"/>
        <property name="dbIndex" value="2"/>
    </bean>

    <!-- 集群连接池配置 -->
    <bean id="redisPoolConfig" class="org.apache.commons.pool2.impl.GenericObjectPoolConfig">
        <property name="maxTotal" value="160"/>
        <property name="maxIdle" value="160"/>
        <property name="minIdle" value="80"/>
        <!-- 获取连接最大等待值 -->
        <property name="maxWaitMillis" value="5000"/>
        <property name="jmxNamePrefix" value="jedis-pool"/>
        <property name="jmxEnabled" value="true"/>
    </bean>

    <!-- 集群版redis操作 -->
    <!--<bean id="redisClusterBuilder" class="com.sohu.tv.builder.RedisClusterBuilder" lazy-init="true">-->
    <!--<constructor-arg value="10024"/>-->
    <!--<property name="jedisPoolConfig" ref="redisPoolConfig"/>-->
    <!--<property name="connectionTimeout" value="2000"/>-->
    <!--<property name="soTimeout" value="1000"/>-->
    <!--</bean>-->

    <!-- 单机版redis 操作 -->
    <bean id="redisStandaloneBuilder" class="com.sohu.tv.builder.RedisStandaloneBuilder" lazy-init="true">
        <constructor-arg value="10024"/>
        <property name="timeout" value="2000"/>
        <property name="poolConfig" ref="redisPoolConfig"/>
    </bean>

    <!-- redisSentine操作 -->
    <bean id="redisSentinelBuilder" class="com.sohu.tv.builder.RedisSentinelBuilder" lazy-init="true">
        <constructor-arg value="10034"/>
        <property name="poolConfig" ref="redisPoolConfig"/>
        <property name="connectionTimeout" value="2000"/>
        <property name="soTimeout" value="1000"/>
    </bean>

    <bean id="systemCacheManage" class="com.elab.cache.spring.manage.SystemCacheManage">
        <property name="cacheClient" ref="redisStandaloneClient"/>
        <property name="timeout" value="300"/>
        <property name="name" value="redisClient"/>
    </bean>

    <bean id="simpleCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
        <property name="caches" ref="systemCacheManage"/>
    </bean>


    <bean id="cacheManager"
          class="org.springframework.cache.support.CompositeCacheManager">
        <property name="cacheManagers">
            <list>
                <ref bean="simpleCacheManager"/>
            </list>
        </property>
        <property name="fallbackToNoOpCache" value="true"/>
    </bean>


</beans>
