Skip to content

Commit 23925d2

Browse files
authored
Merge pull request #197 from cmu-delphi/cache-covidcast-pulls
Cache covidcast pulls
2 parents 2154476 + 430ee5c commit 23925d2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

dashboard/app.R

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,22 @@ library(tsibble)
1010
library(aws.s3)
1111
library(covidcast)
1212
library(stringr)
13+
library(memoise)
1314

1415
source('./common.R')
1516

17+
# Set application-level caching location. Stores up to 1GB of caches. Removes
18+
# least recently used objects first.
19+
shinyOptions(cache = cachem::cache_mem(max_size = 1000 * 1024^2, evict="lru"))
20+
cache <- getShinyOption("cache")
21+
22+
# Since covidcast data updates about once a day. Add date arg to
23+
# covidcast_signal so caches aren't used after that.
24+
covidcast_signal_mem <- function(..., date=Sys.Date()) {
25+
return(covidcast_signal(...))
26+
}
27+
covidcast_signal_mem <- memoise(covidcast_signal_mem, cache = cache)
28+
1629
# All data is fully loaded from AWS
1730
DATA_LOADED = FALSE
1831

@@ -914,7 +927,7 @@ server <- function(input, output, session) {
914927
fetchDate = as.Date(input$asOf) + 1
915928

916929
# Covidcast API call
917-
asOfTruthData = covidcast_signal(data_source = dataSource, signal = targetSignal,
930+
asOfTruthData = covidcast_signal_mem(data_source = dataSource, signal = targetSignal,
918931
start_day = "2020-02-15", end_day = fetchDate,
919932
as_of = fetchDate,
920933
geo_type = location)

docker_dashboard/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ RUN install2.r --error \
1414
aws.s3 \
1515
covidcast \
1616
stringr \
17-
markdown
17+
markdown \
18+
memoise
1819

1920
COPY dist/*rds /srv/shiny-server/
2021
COPY dashboard/* /srv/shiny-server/

0 commit comments

Comments
 (0)