suppressMessages(require("reactr"))

Suggested

read vignette Registry prior to reading this vignette

Overview

The caching mechanism implemented by reactr relies on keeping a registry that stores certain information that are either required or very useful for reacting to respective system states (e.g. for deciding whether an update should be triggered or not).

The rule of thumb for caching is as follows:

If B depends on A and A has not changed: --> use the last cache value if B is requested If B depends on A and A has changed: --> execute the reactive binding function and thus also update the cached value

Checksums

The actual decision is based on a comparison of MD5 checksums of the values of the visible objects as computed by digest::digest().

These are stored in the environment getOption(".reactr")$.registry which is accessible via the convenience function getRegistry().

Besides the actual checksum values, each registry entry - corresponding to the invisible reactive object - also contains some other information that is often required/useful:

Actual registry object

The actual registry object can be retrieved by the convenience function getRegistry():

registry <- getRegistry()
ls(registry)
showRegistry()

Illustrating the role of the registry

## Start with fresh registry //
resetRegistry()

## Set reactive object //
setReactive(id = "x_1", value = 10)
showRegistry()
## --> Object with UID 2fc2e352f72008b90a112f096cd2d029 has been registered
## The object UID was computed by:
computeObjectUid("x_1")

## Retrieve from registry //
(reg_x_1 <- getFromRegistry("x_1"))
## --> same as manually selecting the respective object from the registry
## environment:
registry[[computeObjectUid("x_1")]]

## Inspect structure of invisible object //
ls(reg_x_1, all.names = TRUE)
reg_x_1$.id
reg_x_1$.uid
reg_x_1$.where
reg_x_1$.checksum

## Set additional reactive object //
setReactive(
  id = "x_2", 
  value = function() {
    ## object-ref: {id: x_1}
    x_1 * 2
  }
)
showRegistry()
## --> two entries

## Inspect invisible object associated to visible value `x_2`
reg_x_2 <- getFromRegistry("x_2")
ls(reg_x_2, all.names = TRUE)
reg_x_2$.id
reg_x_2$.uid
reg_x_2$.where
reg_x_2$.checksum
ls(reg_x_2$.refs_pull)
## --> pull references --> reference to `x_1` or UID 2fc2e352f72008b90a112f096cd2d029
reg_x_1_through_x_2 <- reg_x_2$.refs_pull[["2fc2e352f72008b90a112f096cd2d029"]]
## --> same as invisible object behind `x_1` or object with 
## UID 2fc2e352f72008b90a112f096cd2d029 in registry:
identical(reg_x_1, reg_x_1_through_x_2)
## --> that way all references are always accessible which is quite handy
## for a lot of situations, including push updates and integrity checks.

Clean up

rmReactive("x_1")
rmReactive("x_2")
resetRegistry()


rappster/reactr documentation built on May 26, 2019, 11:56 p.m.