Skip to content

Commit

Permalink
Add endpoint for clearing individual source caches
Browse files Browse the repository at this point in the history
  • Loading branch information
amarsan committed Nov 25, 2024
1 parent a1a29cd commit 3eadef7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public void clearCache() {
sources.stream().forEach(this::clearCache);
}

private void clearCache(Source source) {
@Transactional()
public void clearCache(Source source) {
if (sourceAccessor.hasAccess(source)) {
cacheRepository.deleteBySource(source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public void clearCache() {
sources.stream().forEach(this::clearCache);
}

private void clearCache(Source source) {
@Transactional()
public void clearCache(Source source) {
if (sourceAccessor.hasAccess(source)) {
cdmCacheRepository.deleteBySource(source.getSourceId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SourcePermissionSchema extends EntityPermissionSchema {
put("cdmresults:%s:*:get", "Get Achilles reports on Source with SourceKey = %s");
put("cdmresults:%s:conceptRecordCount:post", "Get Achilles concept counts on Source with SourceKey = %s");
put("cdmresults:%s:*:*:get", "Get Achilles reports details on Source with SourceKey = %s");
put("cdmresults:%s:clearcache:post", "Clear the Achilles and CDM results caches on Source with SourceKey = %s");
put("cohortresults:%s:*:*:get", "Get cohort results on Source with SourceKey = %s");
put("cohortresults:%s:*:*:*:get", "Get cohort results details on Source with SourceKey = %s");
put("cohortresults:%s:*:healthcareutilization:*:*:get", "Get cohort results baseline on period for Source with SourceKey = %s");
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/ohdsi/webapi/service/CDMResultsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,25 @@ public JobExecutionResource refreshCache(@PathParam("sourceKey") final String so
}
return new JobExecutionResource();
}

/**
* Clear the cdm_cache and achilles_cache for all sources
*
* @summary Clear the cdm_cache and achilles_cache for all sources
* @return void
* @throws ForbiddenException if the user is not an admin
*/
@POST
@Path("{sourceKey}/clearCache")
@Transactional()
public void clearCacheForSource(@PathParam("sourceKey") final String sourceKey) {
if (!isSecured() || !isAdmin()) {
throw new ForbiddenException();
}
Source source = getSourceRepository().findBySourceKey(sourceKey);
cacheService.clearCache(source);
cdmCacheService.clearCache(source);
}

/**
* Clear the cdm_cache and achilles_cache for all sources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INSERT INTO ${ohdsiSchema}.sec_permission (id, value, description)
SELECT nextval('${ohdsiSchema}.sec_permission_id_seq'),
'cdmresults:clearcache:post',
'Clear the achilles and cdm results caches';
'Clear the Achilles and CDM results caches';

INSERT INTO ${ohdsiSchema}.sec_role_permission (role_id, permission_id)
SELECT sr.id, sp.id
Expand All @@ -12,3 +12,18 @@ WHERE sp."value" in
'cdmresults:clearcache:post'
)
AND sr.name IN ('admin');

INSERT INTO ${ohdsiSchema}.sec_permission (id, value, description)
SELECT nextval('${ohdsiSchema}.sec_permission_id_seq'),
'cdmresults:*:clearcache:post',
'Clear the Achilles and CDM results caches';

INSERT INTO ${ohdsiSchema}.sec_role_permission (role_id, permission_id)
SELECT sr.id, sp.id
FROM ${ohdsiSchema}.sec_permission sp,
${ohdsiSchema}.sec_role sr
WHERE sp."value" in
(
'cdmresults:*:clearcache:post'
)
AND sr.name IN ('admin');

0 comments on commit 3eadef7

Please sign in to comment.