I'm experimenting with klepto (v. 0.1.5.2) to cache some very heavy and time-consuming computations. In particular, I'm using lru_cache
as decorator, coupled with a hdfdir_archive
cache archive.
I managed to persist cache content on disk using the purge=False
option in lru_cache
as suggested in this answer, and it works like a charm. Anyway, I'd recompute the functions once in a while (even with the same input parameters), because some computations are based on data that could change after a certain period of time.
As simple workaround, I thought that the current date could be included in the input parameters of the functions, implementing a custom keymap that checks if the old entry has expired; but I have not found examples of how customize keymaps, so I have no idea if this solution is feasible or could work.
However, I'm wondering if a more elegant or simpler solution is already available in klepto
. In other words, is there an option or policy to automatically invalidate cache entries after a preset period of time?
Thanks!