Device Cache fix
This commit is contained in:
parent
33abe0ebe5
commit
162bf8a1f2
@ -38,17 +38,22 @@ public class DeviceCacheKey implements Serializable {
|
|||||||
this(null, deviceId, null);
|
this(null, deviceId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DeviceCacheKey(TenantId tenantId, DeviceId deviceId) {
|
||||||
|
this(tenantId, deviceId, null);
|
||||||
|
}
|
||||||
|
|
||||||
public DeviceCacheKey(TenantId tenantId, String deviceName) {
|
public DeviceCacheKey(TenantId tenantId, String deviceName) {
|
||||||
this(tenantId, null, deviceName);
|
this(tenantId, null, deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (deviceId != null) {
|
if (deviceId == null) {
|
||||||
|
return tenantId + "_n_" + deviceName;
|
||||||
|
} else if (tenantId == null) {
|
||||||
return deviceId.toString();
|
return deviceId.toString();
|
||||||
} else {
|
} else {
|
||||||
return tenantId + "_n_" + deviceName;
|
return tenantId + "_" + deviceId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -130,15 +130,13 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
|||||||
public Device findDeviceById(TenantId tenantId, DeviceId deviceId) {
|
public Device findDeviceById(TenantId tenantId, DeviceId deviceId) {
|
||||||
log.trace("Executing findDeviceById [{}]", deviceId);
|
log.trace("Executing findDeviceById [{}]", deviceId);
|
||||||
validateId(deviceId, INCORRECT_DEVICE_ID + deviceId);
|
validateId(deviceId, INCORRECT_DEVICE_ID + deviceId);
|
||||||
return cache.getAndPutInTransaction(new DeviceCacheKey(deviceId),
|
|
||||||
() -> {
|
|
||||||
//TODO: possible bug source since sometimes we need to clear cache by tenant id and sometimes by sys tenant id?
|
|
||||||
if (TenantId.SYS_TENANT_ID.equals(tenantId)) {
|
if (TenantId.SYS_TENANT_ID.equals(tenantId)) {
|
||||||
return deviceDao.findById(tenantId, deviceId.getId());
|
return cache.getAndPutInTransaction(new DeviceCacheKey(deviceId),
|
||||||
|
() -> deviceDao.findById(tenantId, deviceId.getId()), true);
|
||||||
} else {
|
} else {
|
||||||
return deviceDao.findDeviceByTenantIdAndId(tenantId, deviceId.getId());
|
return cache.getAndPutInTransaction(new DeviceCacheKey(tenantId, deviceId),
|
||||||
|
() -> deviceDao.findDeviceByTenantIdAndId(tenantId, deviceId.getId()), true);
|
||||||
}
|
}
|
||||||
}, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -259,6 +257,7 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
|||||||
keys.add(new DeviceCacheKey(event.getTenantId(), event.getNewName()));
|
keys.add(new DeviceCacheKey(event.getTenantId(), event.getNewName()));
|
||||||
if (event.getDeviceId() != null) {
|
if (event.getDeviceId() != null) {
|
||||||
keys.add(new DeviceCacheKey(event.getDeviceId()));
|
keys.add(new DeviceCacheKey(event.getDeviceId()));
|
||||||
|
keys.add(new DeviceCacheKey(event.getTenantId(), event.getDeviceId()));
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(event.getOldName()) && !event.getOldName().equals(event.getNewName())) {
|
if (StringUtils.isNotEmpty(event.getOldName()) && !event.getOldName().equals(event.getNewName())) {
|
||||||
keys.add(new DeviceCacheKey(event.getTenantId(), event.getOldName()));
|
keys.add(new DeviceCacheKey(event.getTenantId(), event.getOldName()));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user