Skip to content

Commit ba50f13

Browse files
committed
Clear the cohort definition cache list when creating a cohort definition from a design import.
1 parent a5d6bbe commit ba50f13

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/java/org/ohdsi/webapi/common/DesignImportService.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
import java.util.Optional;
2020
import java.util.function.Predicate;
2121
import java.util.stream.Collectors;
22+
import javax.annotation.Nullable;
23+
import javax.cache.Cache;
24+
import javax.cache.CacheManager;
2225
import org.ohdsi.webapi.analysis.AnalysisConceptSet;
2326
import org.ohdsi.webapi.conceptset.ConceptSetItem;
2427
import org.ohdsi.webapi.service.ConceptSetService;
2528
import org.ohdsi.webapi.service.dto.ConceptSetDTO;
29+
import org.ohdsi.webapi.shiro.PermissionManager;
2630
import org.springframework.core.convert.ConversionService;
2731

2832
@Service
@@ -34,17 +38,20 @@ public class DesignImportService {
3438
private final ConversionService conversionService;
3539
private final ConceptSetService conceptSetService;
3640
private final CohortDefinitionService cohortDefinitionService;
41+
private final CacheManager cacheManager;
3742

3843
public DesignImportService(Security security, UserRepository userRepository, CohortDefinitionRepository cohortRepository,
3944
CohortDefinitionDetailsRepository detailsRepository, ConceptSetService conceptSetService,
40-
ConversionService conversionService, CohortDefinitionService cohortDefinitionService) {
45+
ConversionService conversionService, CohortDefinitionService cohortDefinitionService,
46+
@Nullable CacheManager cacheManager) {
4147
this.security = security;
4248
this.userRepository = userRepository;
4349
this.cohortRepository = cohortRepository;
4450
this.detailsRepository = detailsRepository;
4551
this.conceptSetService = conceptSetService;
4652
this.conversionService = conversionService;
4753
this.cohortDefinitionService = cohortDefinitionService;
54+
this.cacheManager = cacheManager;
4855
}
4956

5057
public ConceptSetDTO persistConceptSet(final AnalysisConceptSet analysisConceptSet) {
@@ -75,6 +82,16 @@ public CohortDefinition persistCohortOrGetExisting(final CohortDefinition cohort
7582
cohort.setName(NameUtils.getNameWithSuffix(cohort.getName(), this::getCdNamesLike));
7683
final CohortDefinition savedCohort = cohortRepository.save(cohort);
7784
detailsRepository.save(details);
85+
86+
// if this is new, we will need to decache the cohort definition list
87+
if (this.cacheManager != null) {
88+
Cache cohortDefCache = cacheManager.getCache(CohortDefinitionService.CachingSetup.COHORT_DEFINITION_LIST_CACHE);
89+
if (cohortDefCache != null) {
90+
cohortDefCache.clear(); // wipes all entries in cohort definition list cache cache
91+
}
92+
}
93+
// permission caching is handled via the EntityInsertEventListener and EntityPermissionSchema.onInsert
94+
7895
return savedCohort;
7996
});
8097
}

0 commit comments

Comments
 (0)