-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented caching for cohort def list, concept set list, permissions, and data sources. Implementation uses ehCache 3.9. Changed editor config to tabs. Made cache endpoints auth restricted.
- Loading branch information
1 parent
67f8816
commit 70dc4e2
Showing
23 changed files
with
655 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.ohdsi.webapi; | ||
|
||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableCaching | ||
public class CacheConfig { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2019 cknoll1. | ||
* | ||
* 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.ohdsi.webapi.cache; | ||
|
||
import java.io.Serializable; | ||
import java.util.Optional; | ||
import javax.cache.management.CacheStatisticsMXBean; | ||
|
||
/** | ||
* | ||
* @author cknoll1 | ||
*/ | ||
public class CacheInfo implements Serializable{ | ||
public String cacheName; | ||
public Long entries; | ||
public CacheStatisticsMXBean cacheStatistics; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2019 cknoll1. | ||
* | ||
* 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.ohdsi.webapi.cache; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.StreamSupport; | ||
import javax.cache.Cache; | ||
import javax.cache.CacheManager; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import org.ohdsi.webapi.util.CacheHelper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* | ||
* @author cknoll1 | ||
*/ | ||
@Path("/cache") | ||
@Component | ||
public class CacheService { | ||
|
||
public static class ClearCacheResult { | ||
|
||
public List<CacheInfo> clearedCaches; | ||
|
||
private ClearCacheResult() { | ||
this.clearedCaches = new ArrayList<>(); | ||
} | ||
} | ||
|
||
private CacheManager cacheManager; | ||
|
||
@Autowired(required = false) | ||
public CacheService(CacheManager cacheManager) { | ||
|
||
this.cacheManager = cacheManager; | ||
} | ||
|
||
public CacheService() { | ||
} | ||
|
||
|
||
@GET | ||
@Path("/") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public List<CacheInfo> getCacheInfoList() { | ||
List<CacheInfo> caches = new ArrayList<>(); | ||
|
||
if (cacheManager == null) return caches; //caching is disabled | ||
|
||
for (String cacheName : cacheManager.getCacheNames()) { | ||
Cache cache = cacheManager.getCache(cacheName); | ||
CacheInfo info = new CacheInfo(); | ||
info.cacheName = cacheName; | ||
info.entries = StreamSupport.stream(cache.spliterator(), false).count(); | ||
info.cacheStatistics = CacheHelper.getCacheStats(cacheManager , cacheName); | ||
caches.add(info); | ||
} | ||
return caches; | ||
} | ||
@GET | ||
@Path("/clear") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public ClearCacheResult clearAll() { | ||
ClearCacheResult result = new ClearCacheResult(); | ||
|
||
for (String cacheName : cacheManager.getCacheNames()) { | ||
Cache cache = cacheManager.getCache(cacheName); | ||
CacheInfo info = new CacheInfo(); | ||
info.cacheName = cacheName; | ||
info.entries = StreamSupport.stream(cache.spliterator(), false).count(); | ||
result.clearedCaches.add(info); | ||
cache.clear(); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.