Added null checks for device cache in-case cache is disabled.

revert-70aa11f8
Harshan Liyanage 8 years ago
parent f70535ed20
commit b8f085da20

@ -55,6 +55,7 @@ public class DeviceCacheManagerImpl implements DeviceCacheManager {
@Override
public void addDeviceToCache(DeviceIdentifier deviceIdentifier, Device device, int tenantId) {
Cache<DeviceCacheKey, Device> lCache = DeviceManagerUtil.getDeviceCache();
if (lCache != null) {
DeviceCacheKey cacheKey = getCacheKey(deviceIdentifier, tenantId);
if (lCache.containsKey(cacheKey)) {
this.updateDeviceInCache(deviceIdentifier, device, tenantId);
@ -62,40 +63,50 @@ public class DeviceCacheManagerImpl implements DeviceCacheManager {
lCache.put(cacheKey, device);
}
}
}
@Override
public void removeDeviceFromCache(DeviceIdentifier deviceIdentifier, int tenantId) {
Cache<DeviceCacheKey, Device> lCache = DeviceManagerUtil.getDeviceCache();
if (lCache != null) {
DeviceCacheKey cacheKey = getCacheKey(deviceIdentifier, tenantId);
if (lCache.containsKey(cacheKey)) {
lCache.remove(cacheKey);
}
}
}
@Override
public void removeDevicesFromCache(List<DeviceCacheKey> deviceList) {
Cache<DeviceCacheKey, Device> lCache = DeviceManagerUtil.getDeviceCache();
if (lCache != null) {
for (DeviceCacheKey cacheKey : deviceList) {
if (lCache.containsKey(cacheKey)) {
lCache.remove(cacheKey);
}
}
}
}
@Override
public void updateDeviceInCache(DeviceIdentifier deviceIdentifier, Device device, int tenantId) {
Cache<DeviceCacheKey, Device> lCache = DeviceManagerUtil.getDeviceCache();
if (lCache != null) {
DeviceCacheKey cacheKey = getCacheKey(deviceIdentifier, tenantId);
if (lCache.containsKey(cacheKey)) {
lCache.replace(cacheKey, device);
}
}
}
@Override
public Device getDeviceFromCache(DeviceIdentifier deviceIdentifier, int tenantId) {
Cache<DeviceCacheKey, Device> lCache = DeviceManagerUtil.getDeviceCache();
if (lCache != null) {
return lCache.get(getCacheKey(deviceIdentifier, tenantId));
}
return null;
}
private DeviceCacheKey getCacheKey(DeviceIdentifier deviceIdentifier, int tenantId) {

Loading…
Cancel
Save