From a24b4de0e30cf3dd0a0c91e166e25d50e02dfa9a Mon Sep 17 00:00:00 2001 From: itning Date: Fri, 12 Apr 2019 11:06:44 +0800 Subject: [PATCH] add expire ttl with default 120 min --- pom.xml | 2 +- .../data/redis/cache/RedisCache.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b0774d0..fbdd296 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ top.yunshu shw_server - 1.7.5-RELEASE + 1.7.6-RELEASE shw_server Student HomeWork Management System diff --git a/src/main/java/org/springframework/data/redis/cache/RedisCache.java b/src/main/java/org/springframework/data/redis/cache/RedisCache.java index 1b70547..9b91bdf 100644 --- a/src/main/java/org/springframework/data/redis/cache/RedisCache.java +++ b/src/main/java/org/springframework/data/redis/cache/RedisCache.java @@ -15,6 +15,7 @@ */ package org.springframework.data.redis.cache; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.support.AbstractValueAdaptingCache; import org.springframework.cache.support.NullValue; @@ -35,6 +36,7 @@ import java.nio.ByteBuffer; import java.util.Set; import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; /** * {@link org.springframework.cache.Cache} implementation using for Redis as underlying store. @@ -49,6 +51,7 @@ */ @SuppressWarnings("all") public class RedisCache extends AbstractValueAdaptingCache { + private static final Logger logger = LoggerFactory.getLogger(RedisCache.class); private static final byte[] BINARY_NULL_VALUE = RedisSerializer.java().serialize(NullValue.INSTANCE); private final String name; @@ -58,7 +61,7 @@ public class RedisCache extends AbstractValueAdaptingCache { private final RedisTemplate redisTemplate; static { - LoggerFactory.getLogger(RedisCache.class).info("Custom RedisCache Class Success Invoked"); + logger.info("Custom RedisCache Class Success Invoked"); } { @@ -157,6 +160,16 @@ public void put(Object key, @Nullable Object value) { } cacheWriter.put(name, createAndConvertCacheKey(key), serializeCacheValue(cacheValue), cacheConfig.getTtl()); + + String inKey = name + "::" + key; + if (redisTemplate.hasKey(inKey)) { + Boolean expire = redisTemplate.expire(inKey, 120, TimeUnit.MINUTES); + if (expire == null || !expire) { + logger.warn("redis key: " + inKey + " expire(should true) is " + expire); + } + } else { + logger.warn("redis key: " + inKey + " does not exist"); + } } /*