Skip to content

Commit 430ee5c

Browse files
committed
cache covidcast pulls
1 parent 1134c92 commit 430ee5c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

dashboard/app.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ library(memoise)
1414

1515
source('./common.R')
1616

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+
1729
# All data is fully loaded from AWS
1830
DATA_LOADED = FALSE
1931

@@ -916,7 +928,7 @@ server <- function(input, output, session) {
916928
fetchDate = as.Date(input$asOf) + 1
917929

918930
# Covidcast API call
919-
asOfTruthData = covidcast_signal(data_source = dataSource, signal = targetSignal,
931+
asOfTruthData = covidcast_signal_mem(data_source = dataSource, signal = targetSignal,
920932
start_day = "2020-02-15", end_day = fetchDate,
921933
as_of = fetchDate,
922934
geo_type = location)

0 commit comments

Comments
 (0)