Module: sage.misc.func_persist
Persistent functions are functions whose values are stored on disk so they do not have to be recomputed.
The inputs to the function must be hashable (so lists are not allowed). Though a hash is used, in the incredibly unlikely event that a hash collision occurs, your function will not return an incorrect result because of this (though the cache might not be used either).
This is meant to be used from .sage
files, not from
library .py
files.
To use this disk caching mechanism, just put
@func_persist
right before your function definition. For
example,
@func_persist def bern(n): "Return the n-th Bernoulli number, caching the result to disk." return bernoulli(n)
bern
as usual, except it will
almost instantly return values that have already been computed, even
if you quit and restart.
The disk cache files are stored by default in the subdirectory
func_persist
of the current working directory, with one file
for each evaluation of the function.
Class: func_persist
@func_persist
right before your function
definition to cache values it computes to disk.
self, f, [dir=func_persist]) |
Special Functions: __call__
See About this document... for information on suggesting changes.