Browse Source

Merge pull request #5961 from YevhenBondarenko/feature/upgrade-script

[3.3.3] version upgrade: added clear redis to cache service
pull/6180/head
Andrew Shvayka 5 years ago
committed by GitHub
parent
commit
9ede8a80ff
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

@ -17,13 +17,14 @@ package org.thingsboard.server.service.install.update;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.Objects;
import java.util.Optional;
@RequiredArgsConstructor
@Service
@ -32,6 +33,8 @@ import java.util.Objects;
public class DefaultCacheCleanupService implements CacheCleanupService {
private final CacheManager cacheManager;
private final Optional<RedisTemplate<String, Object>> redisTemplate;
/**
* Cleanup caches that can not deserialize anymore due to schema upgrade or data update using sql scripts.
@ -59,9 +62,7 @@ public class DefaultCacheCleanupService implements CacheCleanupService {
break;
case "3.3.2":
log.info("Clear cache to upgrade from version 3.3.2 to 3.3.3 ...");
clearCacheByName("devices");
clearCacheByName("deviceProfiles");
clearCacheByName("tenantProfiles");
clearAll();
break;
default:
//Do nothing, since cache cleanup is optional.
@ -78,4 +79,8 @@ public class DefaultCacheCleanupService implements CacheCleanupService {
cache.clear();
}
void clearAll() {
redisTemplate.ifPresent(rt -> rt.execute(connection ->
connection.execute("FLUSHALL"), false));
}
}

Loading…
Cancel
Save