Skip to content

Rebuild cache if the underlying data changed #276

@Hugovdberg

Description

@Hugovdberg

Report an Issue / Request a Feature

I'm submitting a (Check one with "x") :

  • bug report
  • feature request

Issue Severity Classification -

(Check one with "x") :

  • 1 - Severe
  • 2 - Moderate
  • 3 - Low
Expected Behavior

When a file in data/ is changed but the resulting variable exists in the cache the file is not reloaded.

Current Behavior

Currently caching of the data is only done after the variable is loaded into memory, and cached variables are not reloaded if the original file was changed.

Version Information
Possible Solution

Update the cache function to also include a file argument, similar to the depends argument. If the digest of the file has changed reload the file and rebuild the cache. This could be done inside the reader as follows (using the 1.0 reader signature):

csv.reader <- function(file.name, variable.name, ...) {
    cache(variable.name,
          CODE = {
              read.csv(file.name, ...)
          },
          file = file.name
    )
}

This way assigning the variable in global namespace is left to cache, the CODE argument is evaluated as it is normally inside the cache function, and is only updated if the dependency in the file argument changed.

How do you guys feel about this?

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions