Skip to content

Cache invalidation is too strict? #58

Closed
@karldw

Description

@karldw

I noticed that memoise gives different results when a function is source-d vs run line by line, or when a package is installed on one platform vs another. (As Jim Hester mentioned in #55, this happens because the function itself is included in the hash, and I guess the underlying bytecode can differ.)

Below is a quick example that demonstrates the non-caching behavior when the program is run line by line or sourced.

One way to address this, if you think it's a problem that should be addressed, would be to use or borrow from digest::sha1. sha1 is a generic that dispatches to methods that try to look at meaningful differences (see vignette). Note that in the example below, the digests differ, but the sha1s are the same.

Do you think this is worth addressing? It seems like a non-issue for in-memory caches, but could be a pain for on-disk, potentially cross-platform caches.

library(memoise)
library(digest)

cache <- cache_filesystem("temp_Rcache")
fn <- function() {
  message("Actually running the function")
}
message("Digest: ", digest(fn, algo = "xxhash64"), "\nsha1:   ", sha1(fn))
fn_cached <- memoise(fn, cache = cache)
fn_cached()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions