Commit 2880dcf526a6d5155a27ef5ceeb6cb8766dbe998

Authored by Sergey Matvienko
Committed by Andrew Shvayka
1 parent 89fe9514

device cache by id

... ... @@ -27,6 +27,7 @@ import org.springframework.cache.Cache;
27 27 import org.springframework.cache.CacheManager;
28 28 import org.springframework.cache.annotation.CacheEvict;
29 29 import org.springframework.cache.annotation.Cacheable;
  30 +import org.springframework.cache.annotation.Caching;
30 31 import org.springframework.context.annotation.Lazy;
31 32 import org.springframework.stereotype.Service;
32 33 import org.springframework.transaction.annotation.Transactional;
... ... @@ -147,6 +148,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
147 148 return deviceDao.findDeviceInfoById(tenantId, deviceId.getId());
148 149 }
149 150
  151 + @Cacheable(cacheNames = DEVICE_CACHE, key = "{#tenantId, #deviceId}")
150 152 @Override
151 153 public Device findDeviceById(TenantId tenantId, DeviceId deviceId) {
152 154 log.trace("Executing findDeviceById [{}]", deviceId);
... ... @@ -178,13 +180,19 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
178 180 return deviceOpt.orElse(null);
179 181 }
180 182
181   - @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}")
  183 + @Caching(evict= {
  184 + @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}"),
  185 + @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.id}")
  186 + })
182 187 @Override
183 188 public Device saveDeviceWithAccessToken(Device device, String accessToken) {
184 189 return doSaveDevice(device, accessToken);
185 190 }
186 191
187   - @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}")
  192 + @Caching(evict= {
  193 + @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}"),
  194 + @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.id}")
  195 + })
188 196 @Override
189 197 public Device saveDevice(Device device) {
190 198 return doSaveDevice(device, null);
... ... @@ -521,7 +529,10 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
521 529 }
522 530
523 531 @Transactional
524   - @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}")
  532 + @Caching(evict= {
  533 + @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}"),
  534 + @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.id}")
  535 + })
525 536 @Override
526 537 public Device assignDeviceToTenant(TenantId tenantId, Device device) {
527 538 log.trace("Executing assignDeviceToTenant [{}][{}]", tenantId, device);
... ... @@ -546,7 +557,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
546 557 }
547 558
548 559 @Override
549   - @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#profile.tenantId, #provisionRequest.deviceName}")
  560 + @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#profile.tenantId, #provisionRequest.deviceName}") //id is not available yet
550 561 @Transactional
551 562 public Device saveDevice(ProvisionRequest provisionRequest, DeviceProfile profile) {
552 563 Device device = new Device();
... ...