0

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!

1 Answers1

0

I'm the author of klepto. There is no cache in klepto that has time-expiring entries, however, it is on the TODO list.

Mike McKerns
  • 33,715
  • 8
  • 119
  • 139
  • Thanks for the very fast reply! I really appreciate `klepto`: it's a very interesting tool. Do you think that customizing the keymaps could be a possible solution for now? Can you point me out some resources or docs to learn how to customize and use keymaps? – user38320 Jul 23 '18 at 13:57
  • Yes... you can customize the `keymaps`... but what you are looking to do is actually to create a custom archive with a time-expiring cache... that would be done by building a custom `cache`. See `https://github.com/uqfoundation/klepto/blob/master/klepto/_cache.py` – Mike McKerns Jul 23 '18 at 23:04
  • Thanks! I'll try. – user38320 Jul 24 '18 at 14:27