atbug
atbug

Reputation: 838

destination of python persistent memoization

I want to write a decorator that does persistent memoization (memoizing to disk). Since I want to use this decorator for many functions, I have to decide where to save memoizing data for these functions. I googled around and found two solutions:

  1. let the functions decide where to store the memoizing data
  2. automatically determine where to store the data by function names

However, in these two solutions, it is necessary for every function to "know" each other in case of colliding of names (or destinations), which is a smell of bad design.

Thus, my question is, how to avoid such collidings?

Upvotes: 0

Views: 82

Answers (1)

pjz
pjz

Reputation: 43117

Save it in something next to or related to __file__, which is the path to the file the module was loaded from. I believe in some cases it can be a relative path, so you might want to store the memos in that path directly, or turn it into an absolute path or something.

Upvotes: 1

Related Questions