This commit is contained in:
Winston Chang
2018-04-21 10:34:08 -05:00
parent fd90ff7ff7
commit ac92bf98d4
2 changed files with 33 additions and 2 deletions

View File

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

View File

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