我正在寻找一种使用 spring 注释设置 TTL 的方法。
我试过
@CacheEvict(allEntries = true, value = { "mycache" })
@Scheduled(fixedDelay = 5000)
Run Code Online (Sandbox Code Playgroud)
并没有成功穿上@EnableScheduling我的Application.java衣服。
我还尝试@RedisHash(timeToLive=2000)了使用和不@TimeToLive(unit = TimeUnit.SECONDS)使用方法的课程。
然后我试着穿上@EnableRedisRepositories(keyspaceConfiguration = UserKeySpaceConfiguration.class)我的课
public class UserKeySpaceConfiguration extends KeyspaceConfiguration {
/**
* {@inheritDoc}
*
* @see org.springframework.data.redis.core.convert.KeyspaceConfiguration#getKeyspaceSettings(java.lang.Class)
*/
@Override
public KeyspaceSettings getKeyspaceSettings(final Class<?> type) {
final KeyspaceSettings keyspaceSettings = new KeyspaceSettings(type, "user-keyspace");
keyspaceSettings.setTimeToLive(172800L);
return keyspaceSettings;
}
/**
* {@inheritDoc}
* @see org.springframework.data.redis.core.convert.KeyspaceConfiguration#hasSettingsFor(java.lang.Class)
*/
@Override
public boolean hasSettingsFor(final Class<?> type) { …Run Code Online (Sandbox Code Playgroud)