Using Redis with bindCache in Shiny

I'm using Redis to cache some reactive data in Shiny as described in this article : Shiny - Using caching in Shiny to maximize performance


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"))
    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

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.