Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
Yeah, it seems like it. It doesn't look like there is an easy way to do that with the standard library @lru_cache, but you could definitely do it if you rolled your own. I guess the other option if you were going to have it run for a long time (like for a web-app or something) would be to provide a preload function that just exercises those inputs artificially:
defpreload(func,inputs):"""Runs the function with the provided list of inputs,
filling in the cache before expected client use"""forinputininputs:func(input)
I'm working on another post about decorators, so I'll work a preloaded memoization example into it :)
Graduate student in statistics at Duke University. Former dev.to employee. I like to blog about data science on my Medium publication, perplex.city, and on dev.to
Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
Yeah, it seems like it. It doesn't look like there is an easy way to do that with the standard library
@lru_cache
, but you could definitely do it if you rolled your own. I guess the other option if you were going to have it run for a long time (like for a web-app or something) would be to provide apreload
function that just exercises those inputs artificially:I'm working on another post about decorators, so I'll work a preloaded memoization example into it :)
Awesome. Looking forward to your next post
Just went out on Monday! dev.to/rpalo/unwrapping-decorators...