Browse Source

Remove device from cache in case null value cached in the distributed redis

pull/4088/head
Volodymyr Babak 6 years ago
committed by Andrew Shvayka
parent
commit
5391d296f3
  1. 14
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

14
dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

@ -203,6 +203,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
} catch (Exception t) {
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_name_unq_key")) {
// remove device from cache in case null value cached in the distributed redis.
removeDeviceFromCache(device.getTenantId(), device.getName());
throw new DataValidationException("Device with such name already exists!");
} else {
throw t;
@ -281,13 +283,17 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
}
deleteEntityRelations(tenantId, deviceId);
removeDeviceFromCache(tenantId, device.getName());
deviceDao.removeById(tenantId, deviceId.getId());
}
private void removeDeviceFromCache(TenantId tenantId, String name) {
List<Object> list = new ArrayList<>();
list.add(device.getTenantId());
list.add(device.getName());
list.add(tenantId);
list.add(name);
Cache cache = cacheManager.getCache(DEVICE_CACHE);
cache.evict(list);
deviceDao.removeById(tenantId, deviceId.getId());
}
@Override

Loading…
Cancel
Save