container = PersistContainer$new(tempfile())
# Reset the container so that values are cleared
container$reset(all = TRUE)
# Store `1` to 'a' with signature 111 to a non-persist map
# returns 1
container$cache(key = 'a', value = 1, signature = 111, persist = FALSE)
# Replace 'a' with 3
# returns 3
container$cache(key = 'a', value = 3, signature = 111,
persist = TRUE, replace = TRUE)
# check if 'a' exists with signature 111
container$has('a', signature = 111) # TRUE
# When you only have 'a' but no signature
container$has('a') # TRUE
# check if 'a' exists with wrong signature 222
container$has('a', signature = 222) # FALSE
# Store 'a' with 2 with same signature
# will fail and ignore the value (value will not be evaluated if signatured)
# Return 2 (Important! use cached values)
container$cache(key = 'a', value = {
print(123)
return(2)
}, signature = 111, replace = FALSE)
# When no signature is present
# If the key exists (no signature provided), return stored value
# returns 3
container$cache(key = 'a', value = 4)
# replace is TRUE (no signature provided), signature will be some default value
container$cache(key = 'a', value = 2, replace = TRUE)
# destroy the container to free disk space
container$destroy()
Run the code above in your browser using DataLab