| 1 |
# For our purposes, cache objects must support these methods. |
| 2 |
is_cache_object <- function(x) { |
| 3 |
# Use tryCatch in case the object does not support `$`. |
| 4 |
tryCatch( |
| 5 |
is.function(x$get) && is.function(x$set), |
| 6 |
error = function(e) FALSE |
| 7 |
) |
| 8 |
} |
| 9 |
|
| 10 |
# Given a cache object, or string "app" or "session", return appropriate cache |
| 11 |
# object. |
| 12 |
resolve_cache_object <- function(cache, session) { |
| 13 |
if (identical(cache, "app")) { |
| 14 |
cache <- getShinyOption("cache", default = NULL) |
| 15 |
|
| 16 |
} else if (identical(cache, "session")) { |
| 17 |
cache <- session$cache |
| 18 |
} |
| 19 |
|
| 20 |
if (is_cache_object(cache)) { |
| 21 |
return(cache) |
| 22 |
} |
| 23 |
|
| 24 |
stop('`cache` must either be "app", "session", or a cache object with methods, `$get`, and `$set`.') |
| 25 |
} |