Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Commit

Permalink
add expire ttl with default 120 min
Browse files Browse the repository at this point in the history
  • Loading branch information
itning committed Apr 12, 2019
1 parent 77152e4 commit a24b4de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>top.yunshu</groupId>
<artifactId>shw_server</artifactId>
<version>1.7.5-RELEASE</version>
<version>1.7.6-RELEASE</version>
<name>shw_server</name>
<description>Student HomeWork Management System</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
Expand All @@ -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");
}

{
Expand Down Expand Up @@ -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");
}
}

/*
Expand Down

0 comments on commit a24b4de

Please sign in to comment.