Spring Redis 闲置时间

LiuGangQiang 发布于 2016/09/29 16:57
阅读 887
收藏 1

【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”

先贴点Redis的配置文件

<?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:cache="http://www.springframework.org/schema/cache" 
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans.xsd 
						http://www.springframework.org/schema/cache 
						http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">
	<!-- 支持缓存注解 -->
	<cache:annotation-driven cache-manager="cacheManager"/>
	<!-- redis pool相关配置 -->  
    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">  
        <property name="maxIdle" value="300" />        
        <property name="maxWaitMillis" value="3000" />  
        <property name="testOnBorrow" value="true" />  
    </bean> 
    
	<!-- jedis客户端连接工厂 -->
	<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" >
			<property name="poolConfig" ref="poolConfig" />  
			<property name="database" value="0" />  
	        <property name="port" value="${redis.port}" />  
	        <property name="hostName" value="${redis.host}" />
	       <!--  <property name="password" value="${redis.password}" />   -->
	</bean>

	<!-- redisTemplate模板 -->
	<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
		<property name="connectionFactory" ref="jedisConnectionFactory" />
	</bean>
   
   <!-- redis缓存管理器 -->
  <bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager">
  	 <constructor-arg  name="redisOperations" ref="redisTemplate"/>
  	 <!-- 是否事务提交,如果事务回滚,缓存也回滚,默认false -->  
     <property name="transactionAware" value="true" />  
  	 <property name="expires">
  	 	<map>
  	 		<entry key="userCache"  value="1800"/>
  	 	</map>
  	 </property>
  </bean> 
</beans>



其中
<entry key="userCache"  value="1800"/>



这里代表了名为userCahe这个缓存的过期时间为1800S 这是默认都支持的

但是现在有这么个需求就是我需要给userCache设置最大空闲时间 假如为30S 意思就是30S内没人访问也就失效 如果30s内有操作它那么闲置时间又重置一直直到缓存过期(1800s)或者又有30s没操作它就会失效这个怎么实现 或者说怎么配置

加载中
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部