Showing
1 changed file
with
13 additions
and
0 deletions
... | ... | @@ -21,6 +21,8 @@ import org.apache.commons.lang3.StringUtils; |
21 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
22 | 22 | import org.springframework.cache.Cache; |
23 | 23 | import org.springframework.cache.CacheManager; |
24 | +import org.springframework.cache.annotation.CacheEvict; | |
25 | +import org.springframework.cache.annotation.Cacheable; | |
24 | 26 | import org.springframework.stereotype.Service; |
25 | 27 | import org.thingsboard.server.common.data.Customer; |
26 | 28 | import org.thingsboard.server.common.data.EntityView; |
... | ... | @@ -41,6 +43,8 @@ import org.thingsboard.server.dao.tenant.TenantDao; |
41 | 43 | import java.util.ArrayList; |
42 | 44 | import java.util.List; |
43 | 45 | |
46 | +import static org.thingsboard.server.common.data.CacheConstants.DEVICE_CACHE; | |
47 | +import static org.thingsboard.server.common.data.CacheConstants.ENTITY_VIEW_CACHE; | |
44 | 48 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
45 | 49 | import static org.thingsboard.server.dao.service.Validator.validateId; |
46 | 50 | import static org.thingsboard.server.dao.service.Validator.validatePageLink; |
... | ... | @@ -68,6 +72,10 @@ public class EntityViewServiceImpl extends AbstractEntityService |
68 | 72 | @Autowired |
69 | 73 | private CustomerDao customerDao; |
70 | 74 | |
75 | + @Autowired | |
76 | + private CacheManager cacheManager; | |
77 | + | |
78 | + @Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityViewId}") | |
71 | 79 | @Override |
72 | 80 | public EntityView findEntityViewById(EntityViewId entityViewId) { |
73 | 81 | log.trace("Executing findEntityViewById [{}]", entityViewId); |
... | ... | @@ -83,6 +91,7 @@ public class EntityViewServiceImpl extends AbstractEntityService |
83 | 91 | .orElse(null); |
84 | 92 | } |
85 | 93 | |
94 | + @CacheEvict(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityView.id}") | |
86 | 95 | @Override |
87 | 96 | public EntityView saveEntityView(EntityView entityView) { |
88 | 97 | log.trace("Executing save entity view [{}]", entityView); |
... | ... | @@ -107,12 +116,14 @@ public class EntityViewServiceImpl extends AbstractEntityService |
107 | 116 | @Override |
108 | 117 | public void deleteEntityView(EntityViewId entityViewId) { |
109 | 118 | log.trace("Executing deleteEntityView [{}]", entityViewId); |
119 | + Cache cache = cacheManager.getCache(ENTITY_VIEW_CACHE); | |
110 | 120 | validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId); |
111 | 121 | deleteEntityRelations(entityViewId); |
112 | 122 | EntityView entityView = entityViewDao.findById(entityViewId.getId()); |
113 | 123 | List<Object> list = new ArrayList<>(); |
114 | 124 | list.add(entityView.getTenantId()); |
115 | 125 | list.add(entityView.getName()); |
126 | + cache.evict(list); | |
116 | 127 | entityViewDao.removeById(entityViewId.getId()); |
117 | 128 | } |
118 | 129 | |
... | ... | @@ -125,6 +136,7 @@ public class EntityViewServiceImpl extends AbstractEntityService |
125 | 136 | return new TextPageData<>(entityViews, pageLink); |
126 | 137 | } |
127 | 138 | |
139 | + @Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #entityId, #pageLink}") | |
128 | 140 | @Override |
129 | 141 | public TextPageData<EntityView> findEntityViewByTenantIdAndEntityId(TenantId tenantId, EntityId entityId, |
130 | 142 | TextPageLink pageLink) { |
... | ... | @@ -164,6 +176,7 @@ public class EntityViewServiceImpl extends AbstractEntityService |
164 | 176 | return new TextPageData<>(entityViews, pageLink); |
165 | 177 | } |
166 | 178 | |
179 | + @Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #customerId, #entityId, #pageLink}") | |
167 | 180 | @Override |
168 | 181 | public TextPageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndEntityId(TenantId tenantId, |
169 | 182 | CustomerId customerId, | ... | ... |