I’m looking to build a caching decorator that given a function caches the result of the function to a location specified in the decoration. Something like this:
@cacheable('/path/to/cache/file') def my_function(a, b, c): return 'something'
The argument to the decorator is completely separate from the argument to the function it’s wrapping. I’ve looked at quite a few examples but I’m not quite getting how to do this – is it possible to have an argument for the decorator that’s unrelated to and not passed to the wrapped function?
The idea is that your decorator is a function returning a decorator.
FIRST Write your decorator as if you knew your argument was a global variable. Let’s say something like:
–
THEN Write a function that takes cachepath as an arg and return your decorator.
–