Commit 2880dcf526a6d5155a27ef5ceeb6cb8766dbe998
Committed by
Andrew Shvayka
1 parent
89fe9514
device cache by id
Showing
1 changed file
with
15 additions
and
4 deletions
@@ -27,6 +27,7 @@ import org.springframework.cache.Cache; | @@ -27,6 +27,7 @@ import org.springframework.cache.Cache; | ||
27 | import org.springframework.cache.CacheManager; | 27 | import org.springframework.cache.CacheManager; |
28 | import org.springframework.cache.annotation.CacheEvict; | 28 | import org.springframework.cache.annotation.CacheEvict; |
29 | import org.springframework.cache.annotation.Cacheable; | 29 | import org.springframework.cache.annotation.Cacheable; |
30 | +import org.springframework.cache.annotation.Caching; | ||
30 | import org.springframework.context.annotation.Lazy; | 31 | import org.springframework.context.annotation.Lazy; |
31 | import org.springframework.stereotype.Service; | 32 | import org.springframework.stereotype.Service; |
32 | import org.springframework.transaction.annotation.Transactional; | 33 | import org.springframework.transaction.annotation.Transactional; |
@@ -147,6 +148,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -147,6 +148,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
147 | return deviceDao.findDeviceInfoById(tenantId, deviceId.getId()); | 148 | return deviceDao.findDeviceInfoById(tenantId, deviceId.getId()); |
148 | } | 149 | } |
149 | 150 | ||
151 | + @Cacheable(cacheNames = DEVICE_CACHE, key = "{#tenantId, #deviceId}") | ||
150 | @Override | 152 | @Override |
151 | public Device findDeviceById(TenantId tenantId, DeviceId deviceId) { | 153 | public Device findDeviceById(TenantId tenantId, DeviceId deviceId) { |
152 | log.trace("Executing findDeviceById [{}]", deviceId); | 154 | log.trace("Executing findDeviceById [{}]", deviceId); |
@@ -178,13 +180,19 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -178,13 +180,19 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
178 | return deviceOpt.orElse(null); | 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 | @Override | 187 | @Override |
183 | public Device saveDeviceWithAccessToken(Device device, String accessToken) { | 188 | public Device saveDeviceWithAccessToken(Device device, String accessToken) { |
184 | return doSaveDevice(device, accessToken); | 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 | @Override | 196 | @Override |
189 | public Device saveDevice(Device device) { | 197 | public Device saveDevice(Device device) { |
190 | return doSaveDevice(device, null); | 198 | return doSaveDevice(device, null); |
@@ -521,7 +529,10 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -521,7 +529,10 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
521 | } | 529 | } |
522 | 530 | ||
523 | @Transactional | 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 | @Override | 536 | @Override |
526 | public Device assignDeviceToTenant(TenantId tenantId, Device device) { | 537 | public Device assignDeviceToTenant(TenantId tenantId, Device device) { |
527 | log.trace("Executing assignDeviceToTenant [{}][{}]", tenantId, device); | 538 | log.trace("Executing assignDeviceToTenant [{}][{}]", tenantId, device); |
@@ -546,7 +557,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -546,7 +557,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
546 | } | 557 | } |
547 | 558 | ||
548 | @Override | 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 | @Transactional | 561 | @Transactional |
551 | public Device saveDevice(ProvisionRequest provisionRequest, DeviceProfile profile) { | 562 | public Device saveDevice(ProvisionRequest provisionRequest, DeviceProfile profile) { |
552 | Device device = new Device(); | 563 | Device device = new Device(); |