cache_call: Execute a function or retrieve values from a cache

Description Usage Arguments Details Examples

View source: R/cached_call.R

Description

cache_call returns a function call or retrieves a value stored in a cache in order to speed up shiny apps.

Usage

1
2
3
4
5
6
7
8
9
cache_call(
  fn,
  cache,
  cache_params = list(),
  non_cache_params = NULL,
  prefix = NULL,
  cache_depends = NULL,
  custom_id = NULL
)

Arguments

fn

A function to call if the value is not cached

cache

A reactiveValues object to serve as a cache storage

cache_params

Named list of parameters to pass on to fn. These parameters will identify the cached object.

non_cache_params

Named list of parameters to pass on to fn without affecting the identity of the cached item.

prefix

A prefix to add to the hash of a cached object. Serves the purpose of allowing users to more easily identify cached objects.

cache_depends

Extra object that affects the identity of an object.

custom_id

Use a custom id instead of a hash generated by cache_params and cache_depends

Details

This function identifies a value based on the parameters passed on to a function, a prefix and extra objects the user decides to use. This function uses reactiveValues to create a hash dictionary from which to retrieve previously executed funtions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
cache <- reactiveValues()

output$table <- renderDataTable({
  cache_call(
    fn = long_computation,
    cache = cache,
    cache_params = list(arg1 = user_input),
    non_cache_params = list(data = mtcars),
    prefix = "table"
  )
})

proyais/shinyCache documentation built on Dec. 22, 2021, 9:54 a.m.