Browse Source

Merge pull request #6836 from smatvienko-tb/cache-flush-all-for-update-service

[3.4] Flush all cache - Redis cluster support
pull/6845/head
Andrew Shvayka 4 years ago
committed by GitHub
parent
commit
3c85ca2f8b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      application/src/main/java/org/thingsboard/server/service/install/update/DefaultCacheCleanupService.java

13
application/src/main/java/org/thingsboard/server/service/install/update/DefaultCacheCleanupService.java

@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
@ -82,13 +83,21 @@ public class DefaultCacheCleanupService implements CacheCleanupService {
}
void clearCacheByName(final String cacheName) {
log.info("Clearing cache [{}]", cacheName);
Cache cache = cacheManager.getCache(cacheName);
Objects.requireNonNull(cache, "Cache does not exist for name " + cacheName);
cache.clear();
}
void clearAll() {
redisTemplate.ifPresent(rt -> rt.execute(connection ->
connection.execute("FLUSHALL"), false));
if (redisTemplate.isPresent()) {
log.info("Flushing all caches");
redisTemplate.get().execute((RedisCallback<Object>) connection -> {
connection.flushAll();
return null;
});
return;
}
cacheManager.getCacheNames().forEach(this::clearCacheByName);
}
}

Loading…
Cancel
Save