Functions that take a long time to run can slow down experimentation and code development. Instead of running the same function with the same inputs multiple times, the result can be cached to disk and fetched when the function is run with the same arguments again. A simple macro provides this functionality:
using CachedCalls variable = @cached_call f(args; kwargs)
It works by hashing the macro name, values of arguments, and names and values of keyword arguments.
A few things to consider before using the macro:
faccessing global variables?
The second time the macro is used the returned result may be unexpected (if the global variable has changed)
fmutating its inputs or global variables?
The second time the macro is used the inputs/globals will not be mutated.
- The inputs to the macro are considered the same if their hashes are the same.
hash(1) == hash(1.0), and similarly for
DataFrames that differ only by column names.
Additionally, function arguments are differentiated by name only.