How can I implement persistent storage for packages/applications? For example, how can my package have settings which persist across sessions?
I have implemented this more than once in the past. This question is to share our solutions and keep them for future reference. This the kind of application where reliability is paramount because it is often used in packages that may be distributed to many people.
Things to pay attention to:
Compatibility with different Mathematica versions. This is a typical requirement for packages. Solutions must be compatible with 10.0 and all later versions. Earlier version compatibility is even better, but I'm not asking for it because associations are too convenient ...
Persistent storage is useful for package settings. Solutions presented here shouldn't stand in the way of changing the settings format in future versions of the package (adding or removing settings, changing the format, etc.)
Corrupted storage files must be handled gracefully.
Given that this is meant to be included in other packages, simple and short solutions are preferred.
Anything else I didn't think of?
Resourceobject
? $\endgroup$pdflatex
executable permanently, so I use some persistent storage for this. MATLink also need to remember if it should try to use a 32-bit or 64-bit MATLAB. Another possible use case is caching certain information. I'm primarily interested in use cases where the data that needs to be stored is small. $\endgroup$CurrentValue[$FrontEnd, {TaggingRules, "MaTeX", "pdflatexpath"}] = ...
, this is what I am doing (unles I missed the point) $\endgroup$$UserBaseDirectory/ApplicationData/PackageName
, not in the package directory itself. The package directory may get removed when the package is updated. $\endgroup$