diff --git a/R/cache.R b/R/cache.R index ab32d7a7a..e9c1216c2 100644 --- a/R/cache.R +++ b/R/cache.R @@ -95,6 +95,8 @@ DiskCache <- R6Class("DiskCache", private$prune_ <- list(prune) }, + # TODO: Should call has() and return some sentinal object if not present + # Should be atomic ot avoid race conditions. get = function(key) { if (!self$has(key)) { stop("Key not available: ", key) @@ -104,6 +106,12 @@ DiskCache <- R6Class("DiskCache", value }, + mget = function(keys) { + }, + + mset = function(..., .list = NULL) { + }, + set = function(key, value) { # TODO: Make sure key is a safe string self$prune() @@ -115,6 +123,11 @@ DiskCache <- R6Class("DiskCache", file.exists(private$key_to_filename(key)) }, + # Return all keys in the cache + keys = function() { + + }, + remove = function(key) { file.remove(private$key_to_filename(key)) invisible(self) @@ -130,6 +143,14 @@ DiskCache <- R6Class("DiskCache", invisible(self) }, + size = function() { + }, + + # Resets the cache and destroys the containing folder so that no + # one else who shares the data back end can use it anymore. + destroy = function() { + }, + finalize = function() { if (private$reset_on_finalize) { self$reset() @@ -154,6 +175,13 @@ DiskCache <- R6Class("DiskCache", ) ) +# Safely hash an object. If it has any weird things in it that might change, like +# functions or xptrs (?), throw an error. +safe_hash <- function(x) { + +} + + disk_pruner <- function(max_size = 5 * 1024^2, max_age = Inf, discard = c("oldest", "newest"), timetype = c("ctime", "atime", "mtime")) diff --git a/R/render-cached-plot.R b/R/render-cached-plot.R index 29f5b0d7d..89d9fb14b 100644 --- a/R/render-cached-plot.R +++ b/R/render-cached-plot.R @@ -220,14 +220,17 @@ renderCachedPlot <- function(expr, cacheKeyExpr, return() } else if (identical(cache, "app")) { + getShinyOption("appCacheFun")() cacheDir <- file.path(tempdir(), - paste0("shinyapp-", getShinyOption("appToken"), "-", outputName) + paste0("shinyapp-", getShinyOption("appToken")) ) cache <<- DiskCache$new(cacheDir, prune = disk_pruner(max_size = 5*1024^2), reset_on_finalize = FALSE) } else if (identical(cache, "session")) { + session$getCache() + cacheDir <- file.path(tempdir(), - paste0("shinyapp-", getShinyOption("appToken"), "-", session$token, "-", outputName) + paste0("shinyapp-", getShinyOption("appToken"), "-", session$token) ) cache <<- DiskCache$new(cacheDir, prune = disk_pruner(max_size = 5*1024^2), reset_on_finalize = TRUE)