No more redundant EntityCacheManager
This commit is contained in:
parent
c69ba6d02d
commit
5243b873e0
@ -20,7 +20,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||||||
import org.springframework.cache.CacheManager;
|
import org.springframework.cache.CacheManager;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_CACHE;
|
|
||||||
import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_DATA_CACHE;
|
import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_DATA_CACHE;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|||||||
@ -19,10 +19,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||||||
import org.springframework.cache.CacheManager;
|
import org.springframework.cache.CacheManager;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.server.common.data.CacheConstants;
|
import org.thingsboard.server.common.data.CacheConstants;
|
||||||
import org.thingsboard.server.common.data.Device;
|
|
||||||
import org.thingsboard.server.common.data.asset.Asset;
|
import org.thingsboard.server.common.data.asset.Asset;
|
||||||
import org.thingsboard.server.dao.cache.CaffeineTbTransactionalCache;
|
import org.thingsboard.server.dao.cache.CaffeineTbTransactionalCache;
|
||||||
import org.thingsboard.server.dao.device.DeviceCacheKey;
|
|
||||||
|
|
||||||
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "caffeine", matchIfMissing = true)
|
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "caffeine", matchIfMissing = true)
|
||||||
@Service("AssetCache")
|
@Service("AssetCache")
|
||||||
|
|||||||
@ -15,12 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.dao.attributes;
|
package org.thingsboard.server.dao.attributes;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.cache.CacheManager;
|
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
|
||||||
import org.springframework.data.redis.serializer.SerializationException;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.server.cache.CacheSpecsMap;
|
import org.thingsboard.server.cache.CacheSpecsMap;
|
||||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
|
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.thingsboard.server.dao.cache;
|
|
||||||
|
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
|
||||||
|
|
||||||
public interface EntitiesCacheManager {
|
|
||||||
|
|
||||||
void removeAssetFromCacheByName(TenantId tenantId, String name);
|
|
||||||
|
|
||||||
void removeEdgeFromCacheByName(TenantId tenantId, String name);
|
|
||||||
}
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.thingsboard.server.dao.cache;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.cache.Cache;
|
|
||||||
import org.springframework.cache.CacheManager;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import static org.thingsboard.server.common.data.CacheConstants.ASSET_CACHE;
|
|
||||||
import static org.thingsboard.server.common.data.CacheConstants.EDGE_CACHE;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class EntitiesCacheManagerImpl implements EntitiesCacheManager {
|
|
||||||
|
|
||||||
private final CacheManager cacheManager;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAssetFromCacheByName(TenantId tenantId, String name) {
|
|
||||||
Cache cache = cacheManager.getCache(ASSET_CACHE);
|
|
||||||
cache.evict(Arrays.asList(tenantId, name));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeEdgeFromCacheByName(TenantId tenantId, String name) {
|
|
||||||
Cache cache = cacheManager.getCache(EDGE_CACHE);
|
|
||||||
cache.evict(Arrays.asList(tenantId, name));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.dao.device;
|
package org.thingsboard.server.dao.device;
|
||||||
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.leshan.core.SecurityMode;
|
import org.eclipse.leshan.core.SecurityMode;
|
||||||
import org.eclipse.leshan.core.util.SecurityUtil;
|
import org.eclipse.leshan.core.util.SecurityUtil;
|
||||||
|
|||||||
@ -17,11 +17,7 @@ package org.thingsboard.server.dao.device;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.Cache;
|
|
||||||
import org.springframework.cache.CacheManager;
|
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -33,7 +29,6 @@ import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
|||||||
import org.thingsboard.server.common.data.DeviceProfileType;
|
import org.thingsboard.server.common.data.DeviceProfileType;
|
||||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||||
import org.thingsboard.server.common.data.StringUtils;
|
import org.thingsboard.server.common.data.StringUtils;
|
||||||
import org.thingsboard.server.common.data.TenantProfile;
|
|
||||||
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
|
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
|
||||||
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration;
|
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration;
|
||||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
|
||||||
@ -42,24 +37,17 @@ import org.thingsboard.server.common.data.id.DeviceProfileId;
|
|||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.page.PageData;
|
import org.thingsboard.server.common.data.page.PageData;
|
||||||
import org.thingsboard.server.common.data.page.PageLink;
|
import org.thingsboard.server.common.data.page.PageLink;
|
||||||
import org.thingsboard.server.dao.asset.AssetCacheKey;
|
|
||||||
import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
|
import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
|
||||||
import org.thingsboard.server.dao.entity.AbstractEntityService;
|
|
||||||
import org.thingsboard.server.dao.exception.DataValidationException;
|
import org.thingsboard.server.dao.exception.DataValidationException;
|
||||||
import org.thingsboard.server.dao.service.DataValidator;
|
import org.thingsboard.server.dao.service.DataValidator;
|
||||||
import org.thingsboard.server.dao.service.PaginatedRemover;
|
import org.thingsboard.server.dao.service.PaginatedRemover;
|
||||||
import org.thingsboard.server.dao.service.Validator;
|
import org.thingsboard.server.dao.service.Validator;
|
||||||
import org.thingsboard.server.dao.tenant.TenantProfileCacheKey;
|
|
||||||
import org.thingsboard.server.dao.tenant.TenantProfileEvictEvent;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import static org.thingsboard.server.common.data.CacheConstants.DEVICE_PROFILE_CACHE;
|
|
||||||
import static org.thingsboard.server.dao.service.Validator.validateId;
|
import static org.thingsboard.server.dao.service.Validator.validateId;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|||||||
@ -28,7 +28,6 @@ import org.thingsboard.server.common.data.id.TenantId;
|
|||||||
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
|
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
|
||||||
import org.thingsboard.server.dao.asset.AssetDao;
|
import org.thingsboard.server.dao.asset.AssetDao;
|
||||||
import org.thingsboard.server.dao.asset.BaseAssetService;
|
import org.thingsboard.server.dao.asset.BaseAssetService;
|
||||||
import org.thingsboard.server.dao.cache.EntitiesCacheManager;
|
|
||||||
import org.thingsboard.server.dao.customer.CustomerDao;
|
import org.thingsboard.server.dao.customer.CustomerDao;
|
||||||
import org.thingsboard.server.dao.exception.DataValidationException;
|
import org.thingsboard.server.dao.exception.DataValidationException;
|
||||||
import org.thingsboard.server.dao.service.DataValidator;
|
import org.thingsboard.server.dao.service.DataValidator;
|
||||||
@ -53,9 +52,6 @@ public class AssetDataValidator extends DataValidator<Asset> {
|
|||||||
@Lazy
|
@Lazy
|
||||||
private TbTenantProfileCache tenantProfileCache;
|
private TbTenantProfileCache tenantProfileCache;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EntitiesCacheManager cacheManager;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateCreate(TenantId tenantId, Asset asset) {
|
protected void validateCreate(TenantId tenantId, Asset asset) {
|
||||||
DefaultTenantProfileConfiguration profileConfiguration =
|
DefaultTenantProfileConfiguration profileConfiguration =
|
||||||
@ -72,9 +68,6 @@ public class AssetDataValidator extends DataValidator<Asset> {
|
|||||||
if (old == null) {
|
if (old == null) {
|
||||||
throw new DataValidationException("Can't update non existing asset!");
|
throw new DataValidationException("Can't update non existing asset!");
|
||||||
}
|
}
|
||||||
if (!old.getName().equals(asset.getName())) {
|
|
||||||
cacheManager.removeAssetFromCacheByName(tenantId, old.getName());
|
|
||||||
}
|
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import org.thingsboard.server.common.data.id.CustomerId;
|
|||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.ota.OtaPackageType;
|
import org.thingsboard.server.common.data.ota.OtaPackageType;
|
||||||
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
|
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
|
||||||
import org.thingsboard.server.dao.cache.EntitiesCacheManager;
|
|
||||||
import org.thingsboard.server.dao.customer.CustomerDao;
|
import org.thingsboard.server.dao.customer.CustomerDao;
|
||||||
import org.thingsboard.server.dao.device.DeviceDao;
|
import org.thingsboard.server.dao.device.DeviceDao;
|
||||||
import org.thingsboard.server.dao.exception.DataValidationException;
|
import org.thingsboard.server.dao.exception.DataValidationException;
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import org.thingsboard.server.common.data.Tenant;
|
|||||||
import org.thingsboard.server.common.data.edge.Edge;
|
import org.thingsboard.server.common.data.edge.Edge;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.dao.cache.EntitiesCacheManager;
|
|
||||||
import org.thingsboard.server.dao.customer.CustomerDao;
|
import org.thingsboard.server.dao.customer.CustomerDao;
|
||||||
import org.thingsboard.server.dao.edge.EdgeDao;
|
import org.thingsboard.server.dao.edge.EdgeDao;
|
||||||
import org.thingsboard.server.dao.exception.DataValidationException;
|
import org.thingsboard.server.dao.exception.DataValidationException;
|
||||||
@ -39,7 +38,6 @@ public class EdgeDataValidator extends DataValidator<Edge> {
|
|||||||
private final EdgeDao edgeDao;
|
private final EdgeDao edgeDao;
|
||||||
private final TenantDao tenantDao;
|
private final TenantDao tenantDao;
|
||||||
private final CustomerDao customerDao;
|
private final CustomerDao customerDao;
|
||||||
private final EntitiesCacheManager cacheManager;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateCreate(TenantId tenantId, Edge edge) {
|
protected void validateCreate(TenantId tenantId, Edge edge) {
|
||||||
@ -47,11 +45,7 @@ public class EdgeDataValidator extends DataValidator<Edge> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Edge validateUpdate(TenantId tenantId, Edge edge) {
|
protected Edge validateUpdate(TenantId tenantId, Edge edge) {
|
||||||
Edge old = edgeDao.findById(edge.getTenantId(), edge.getId().getId());
|
return edgeDao.findById(edge.getTenantId(), edge.getId().getId());
|
||||||
if (!old.getName().equals(edge.getName())) {
|
|
||||||
cacheManager.removeEdgeFromCacheByName(tenantId, old.getName());
|
|
||||||
}
|
|
||||||
return old;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -18,7 +18,6 @@ package org.thingsboard.server.dao.tenant;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -40,7 +39,6 @@ import org.thingsboard.server.dao.service.Validator;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.thingsboard.server.common.data.CacheConstants.TENANT_PROFILE_CACHE;
|
|
||||||
import static org.thingsboard.server.dao.service.Validator.validateId;
|
import static org.thingsboard.server.dao.service.Validator.validateId;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user