-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #432 from RADAR-base/cacheQuestionnaires
Cache questionnaires and standardize github client access
- Loading branch information
Showing
13 changed files
with
346 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,5 @@ bin/ | |
|
||
docker/prod | ||
|
||
*__pycache__ | ||
*__pycache__ | ||
google-credentials.json |
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
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
36 changes: 36 additions & 0 deletions
36
src/main/java/org/radarbase/appserver/service/GithubService.java
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,36 @@ | ||
package org.radarbase.appserver.service; | ||
|
||
import org.radarbase.appserver.util.CachedFunction; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.beans.factory.config.ConfigurableBeanFactory; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.Duration; | ||
|
||
@Component | ||
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) | ||
public class GithubService { | ||
|
||
private final transient CachedFunction<String, String> cachedGetContent; | ||
|
||
@Autowired | ||
public GithubService( | ||
GithubClient githubClient, | ||
@Value("${security.github.cache.duration:3600}") | ||
int cacheTime, | ||
@Value("${security.github.cache.retryDuration:60}") | ||
int retryTime, | ||
@Value("${security.github.cache.size:10000}") | ||
int maxSize) { | ||
this.cachedGetContent = new CachedFunction<>(githubClient::getGithubContent, | ||
Duration.ofSeconds(cacheTime), | ||
Duration.ofSeconds(retryTime), | ||
maxSize); | ||
} | ||
|
||
public String getGithubContent(String url) throws Exception { | ||
return this.cachedGetContent.applyWithException(url); | ||
} | ||
} |
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.