Commit 2287b05d9903fefe29b5a74141fa1e063023a3b9

Authored by Sergey Matvienko
Committed by Andrew Shvayka
1 parent 2880dcf5

device cache: removeDeviceFromCacheById added

@@ -258,6 +258,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -258,6 +258,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
258 if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_name_unq_key")) { 258 if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_name_unq_key")) {
259 // remove device from cache in case null value cached in the distributed redis. 259 // remove device from cache in case null value cached in the distributed redis.
260 removeDeviceFromCacheByName(device.getTenantId(), device.getName()); 260 removeDeviceFromCacheByName(device.getTenantId(), device.getName());
  261 + removeDeviceFromCacheById(device.getTenantId(), device.getId());
261 throw new DataValidationException("Device with such name already exists!"); 262 throw new DataValidationException("Device with such name already exists!");
262 } else { 263 } else {
263 throw t; 264 throw t;
@@ -335,6 +336,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -335,6 +336,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
335 deleteEntityRelations(tenantId, deviceId); 336 deleteEntityRelations(tenantId, deviceId);
336 337
337 removeDeviceFromCacheByName(tenantId, device.getName()); 338 removeDeviceFromCacheByName(tenantId, device.getName());
  339 + removeDeviceFromCacheById(tenantId, device.getId());
338 340
339 deviceDao.removeById(tenantId, deviceId.getId()); 341 deviceDao.removeById(tenantId, deviceId.getId());
340 } 342 }
@@ -344,6 +346,11 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -344,6 +346,11 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
344 cache.evict(Arrays.asList(tenantId, name)); 346 cache.evict(Arrays.asList(tenantId, name));
345 } 347 }
346 348
  349 + private void removeDeviceFromCacheById(TenantId tenantId, DeviceId deviceId) {
  350 + Cache cache = cacheManager.getCache(DEVICE_CACHE);
  351 + cache.evict(Arrays.asList(tenantId, deviceId));
  352 + }
  353 +
347 @Override 354 @Override
348 public PageData<Device> findDevicesByTenantId(TenantId tenantId, PageLink pageLink) { 355 public PageData<Device> findDevicesByTenantId(TenantId tenantId, PageLink pageLink) {
349 log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); 356 log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
@@ -557,7 +564,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -557,7 +564,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
557 } 564 }
558 565
559 @Override 566 @Override
560 - @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#profile.tenantId, #provisionRequest.deviceName}") //id is not available yet 567 + @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#profile.tenantId, #provisionRequest.deviceName}")
561 @Transactional 568 @Transactional
562 public Device saveDevice(ProvisionRequest provisionRequest, DeviceProfile profile) { 569 public Device saveDevice(ProvisionRequest provisionRequest, DeviceProfile profile) {
563 Device device = new Device(); 570 Device device = new Device();
@@ -599,6 +606,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -599,6 +606,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
599 throw new ProvisionFailedException(ProvisionResponseStatus.FAILURE.name()); 606 throw new ProvisionFailedException(ProvisionResponseStatus.FAILURE.name());
600 } 607 }
601 } 608 }
  609 + removeDeviceFromCacheById(savedDevice.getTenantId(), savedDevice.getId());
602 return savedDevice; 610 return savedDevice;
603 } 611 }
604 612
@@ -688,6 +696,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -688,6 +696,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
688 } 696 }
689 if (!old.getName().equals(device.getName())) { 697 if (!old.getName().equals(device.getName())) {
690 removeDeviceFromCacheByName(tenantId, old.getName()); 698 removeDeviceFromCacheByName(tenantId, old.getName());
  699 + removeDeviceFromCacheById(tenantId, old.getId());
691 } 700 }
692 } 701 }
693 702