Save cache metadata in JSON format #1353
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes the file format used for storing cached metadata from pickle to JSON. It eliminates the problem that pickled files written using one version of Python might not be readable using a different version of python, and an extra benefit is that such files are now human readable so easier to understand/debug.
All loading and saving of cache metadata is now performed in specific low-level functions
CacheMetadata._load
andCacheMetadata._save
.We still support the reading of cached metadata from pickled files so that pre-existing caches should still be usable. Such files will be saved as JSON the next time they are saved.
The implementation uses
ujson
if it is installed, falling back tojson
. This is the same approach used inReferenceFileSystem
.The only slight complexity here is that we have to test both JSON and pickle formats in CI, so I have added a private boolean attribute
CacheMetadata._force_save_pickle
. This should only be used in tests, not by end users. If set toTrue
subsequent saves are in pickle format so we can simulate old pickled metadata to confirm it can still be read and is converted to JSON on next save.Fixes #825.