Hello!
I'm using Redis to cache some reactive data in Shiny as described in this article : Shiny - Using caching in Shiny to maximize performance
library(shiny)
library(redux)
library(R6)
RedisCache <- R6Class("RedisCache",
public = list(
initialize = function(..., namespace = NULL) {
private$r <- redux::hiredis(...)
private$namespace <- namespace
},
get = function(key) {
key <- paste0(private$namespace, "-", key)
s_value <- private$r$GET(key)
if (is.null(s_value)) {
return(structure(list(), class = "key_missing"))
}
unserialize(s_value)
},
set = function(key, value, ex) {
key <- paste0(private$namespace, "-", key)
s_value <- serialize(value, NULL)
private$r$SET(key, s_value, EX=ex)
}
),
private = list(
r = NULL,
namespace = NULL
)
)
I modified a the R6 class to be able to add the EX parameter ( expire time, in seconds) to the SET method.
data <- reactive({
db%>% filter(date==input$choise_date)
}) %>%
bindCache(input$choise_date, cache= session$cache)
I want to cache data and if the value of input$choise_date is the current day then make sure to remove the key when the specified amount of time elapsed.
Please help.
Thank you