How to use lru_cache for static method and with unhashable arguments like lists in python
I have tried using methodtools lru_cache method. It gives an error that call is not working.
How to use lru_cache for static method and with unhashable arguments like lists in python
I have tried using methodtools lru_cache method. It gives an error that call is not working.
Copyright © 2021 Jogjafile Inc.
You could use a separate decorator to sanitize the inputs. Something like this:
However, getting this right (and fast) in a generic fashion is a bit tedious. Note how I left out keyword arguments for simplicity.
An easier solution is to use an uncached public interface with an lru-cached private implementation. Something like this: