Fix cache key for device cache
This commit is contained in:
parent
5702d9654a
commit
33abe0ebe5
@ -34,8 +34,8 @@ public class DeviceCacheKey implements Serializable {
|
||||
private final DeviceId deviceId;
|
||||
private final String deviceName;
|
||||
|
||||
public DeviceCacheKey(TenantId tenantId, DeviceId deviceId) {
|
||||
this(tenantId, deviceId, null);
|
||||
public DeviceCacheKey(DeviceId deviceId) {
|
||||
this(null, deviceId, null);
|
||||
}
|
||||
|
||||
public DeviceCacheKey(TenantId tenantId, String deviceName) {
|
||||
@ -45,7 +45,7 @@ public class DeviceCacheKey implements Serializable {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (deviceId != null) {
|
||||
return tenantId + "_" + deviceId;
|
||||
return deviceId.toString();
|
||||
} else {
|
||||
return tenantId + "_n_" + deviceName;
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
||||
public Device findDeviceById(TenantId tenantId, DeviceId deviceId) {
|
||||
log.trace("Executing findDeviceById [{}]", deviceId);
|
||||
validateId(deviceId, INCORRECT_DEVICE_ID + deviceId);
|
||||
return cache.getAndPutInTransaction(new DeviceCacheKey(tenantId, 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)) {
|
||||
@ -258,7 +258,7 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
|
||||
List<DeviceCacheKey> keys = new ArrayList<>(3);
|
||||
keys.add(new DeviceCacheKey(event.getTenantId(), event.getNewName()));
|
||||
if (event.getDeviceId() != null) {
|
||||
keys.add(new DeviceCacheKey(event.getTenantId(), event.getDeviceId()));
|
||||
keys.add(new DeviceCacheKey(event.getDeviceId()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(event.getOldName()) && !event.getOldName().equals(event.getNewName())) {
|
||||
keys.add(new DeviceCacheKey(event.getTenantId(), event.getOldName()));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user