Commit 2287b05d9903fefe29b5a74141fa1e063023a3b9
Committed by
Andrew Shvayka
1 parent
2880dcf5
device cache: removeDeviceFromCacheById added
Showing
1 changed file
with
10 additions
and
1 deletions
... | ... | @@ -258,6 +258,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
258 | 258 | if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_name_unq_key")) { |
259 | 259 | // remove device from cache in case null value cached in the distributed redis. |
260 | 260 | removeDeviceFromCacheByName(device.getTenantId(), device.getName()); |
261 | + removeDeviceFromCacheById(device.getTenantId(), device.getId()); | |
261 | 262 | throw new DataValidationException("Device with such name already exists!"); |
262 | 263 | } else { |
263 | 264 | throw t; |
... | ... | @@ -335,6 +336,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
335 | 336 | deleteEntityRelations(tenantId, deviceId); |
336 | 337 | |
337 | 338 | removeDeviceFromCacheByName(tenantId, device.getName()); |
339 | + removeDeviceFromCacheById(tenantId, device.getId()); | |
338 | 340 | |
339 | 341 | deviceDao.removeById(tenantId, deviceId.getId()); |
340 | 342 | } |
... | ... | @@ -344,6 +346,11 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
344 | 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 | 354 | @Override |
348 | 355 | public PageData<Device> findDevicesByTenantId(TenantId tenantId, PageLink pageLink) { |
349 | 356 | log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
... | ... | @@ -557,7 +564,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
557 | 564 | } |
558 | 565 | |
559 | 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 | 568 | @Transactional |
562 | 569 | public Device saveDevice(ProvisionRequest provisionRequest, DeviceProfile profile) { |
563 | 570 | Device device = new Device(); |
... | ... | @@ -599,6 +606,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
599 | 606 | throw new ProvisionFailedException(ProvisionResponseStatus.FAILURE.name()); |
600 | 607 | } |
601 | 608 | } |
609 | + removeDeviceFromCacheById(savedDevice.getTenantId(), savedDevice.getId()); | |
602 | 610 | return savedDevice; |
603 | 611 | } |
604 | 612 | |
... | ... | @@ -688,6 +696,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
688 | 696 | } |
689 | 697 | if (!old.getName().equals(device.getName())) { |
690 | 698 | removeDeviceFromCacheByName(tenantId, old.getName()); |
699 | + removeDeviceFromCacheById(tenantId, old.getId()); | |
691 | 700 | } |
692 | 701 | } |
693 | 702 | ... | ... |