Remove device from cache in case null value cached in the distributed redis
This commit is contained in:
parent
0f3d320933
commit
5391d296f3
@ -203,6 +203,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
|
|||||||
} catch (Exception t) {
|
} catch (Exception t) {
|
||||||
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
|
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
|
||||||
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_name_unq_key")) {
|
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!");
|
throw new DataValidationException("Device with such name already exists!");
|
||||||
} else {
|
} else {
|
||||||
throw t;
|
throw t;
|
||||||
@ -281,15 +283,19 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
|
|||||||
}
|
}
|
||||||
deleteEntityRelations(tenantId, deviceId);
|
deleteEntityRelations(tenantId, deviceId);
|
||||||
|
|
||||||
List<Object> list = new ArrayList<>();
|
removeDeviceFromCache(tenantId, device.getName());
|
||||||
list.add(device.getTenantId());
|
|
||||||
list.add(device.getName());
|
|
||||||
Cache cache = cacheManager.getCache(DEVICE_CACHE);
|
|
||||||
cache.evict(list);
|
|
||||||
|
|
||||||
deviceDao.removeById(tenantId, deviceId.getId());
|
deviceDao.removeById(tenantId, deviceId.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeDeviceFromCache(TenantId tenantId, String name) {
|
||||||
|
List<Object> list = new ArrayList<>();
|
||||||
|
list.add(tenantId);
|
||||||
|
list.add(name);
|
||||||
|
Cache cache = cacheManager.getCache(DEVICE_CACHE);
|
||||||
|
cache.evict(list);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageData<Device> findDevicesByTenantId(TenantId tenantId, PageLink pageLink) {
|
public PageData<Device> findDevicesByTenantId(TenantId tenantId, PageLink pageLink) {
|
||||||
log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
|
log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user