-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cache management features (#799)
* Add cache management features. We add a cache management layer on top of Pystow. This takes the form of two classes (both in `oaklib.utilities.caching`): * one representing the cache management policy, i.e. the logic dictating whether a cached file (if present) should be refreshed or not; * one representing the file cache itself. The policy is set once by the main entry point method, using either a default policy of refreshing cached data after 7 days, or another policy explicitly selected by the user with the new `--caching` option. The class that represents the file cache is the one that the rest of OAK should interact with whenever an access to caching data is needed. Ultimately, all calls to the Pystow module should be replaced to calls to FileCache, the use of Pystow becoming an implementation detail entirely encapsulated in FileCache. * Re-implement cache-ls and cache-clear. Add new methods to the FileCache class to (1) get the list of files present in the cache and (2) delete files in the cache. Replace the implementations of the cache-ls and cache-clear commands to use the new methods, so that the details of cache listing and clearing remain encapsulated in FileCache. As a side-effect, this automatically fixes the issue that cache listing was only working on Unix-like systems, since the FileCache implementation is pure Python and does not rely on the ls(1) Unix command. * Implement the cache reset policy. The intended difference between the REFRESH and RESET caching policies is that, when a cache lookup is attempted, REFRESH should cause the file that was looked up -- and only that file -- to be refreshed, leaving any other file that may be present in the cache untouched. RESET, on the other hand, should entirely clear the cache, so that not only the file that was looked up should be refreshed, but any other file that may looked up in a subsequent call should be refreshed as well. This commit implements the intended behaviour for the RESET policy. * Fix forced refresh for future timestamps and add tests. In principle, we should never have to compare a timestamp representing a future date when we check whether a cached file should be refreshed. However, files with bogus mtime values and/or computers configured with a bogus system time are certainly not uncommon, so encountering a timestamp higher than the current time can (and will) definitely happen. Under an "always refresh" policy, a refresh must be triggered even if the cached file appears to "newer than now", so we explicitly implement that behaviour here. We also add a complete test fixture for the CachePolicy class. * Add some documentation for --caching. In the SQLite tutorial, in the section that briefly mentions that automatically downloaded SQLite files are cached in ``.data/oaklib``, we describe in more details how the cache works and how it can be controlled using the `--caching` option. * Add complete documentation for the `--caching` option. Add a new section in the CLI reference documentation to explain how the cache works and how it can be controlled using the `--caching` option. Replace the previous, shorter documentation in the SQLite tutorial by a simple mention of the cache with a link to the newly added reference section. * Allow controlling the cache through a configuration file. This commit adds the possibility to configure the file cache to apply pattern-specific caching policies. This is controlled by a configuration file ($XDG_CONFIG_HOME/ontology-access-kit/cache.conf, under GNU/Linux) containing "pattern=policy" pairs, where pattern is a shell-type globbing pattern and policy is a string of the same type as expected by the newly introduced --caching option. * Misc documentation fix. The "user_config_dir" returned by the Appdirs package under macOS is not in "~/Library/Prefences" but under "~/Library/Application Support" (Appdirs documentation is not up to date). Also, there is no need to mention the roaming directory under Windows, as Appdirs will never use that directory unless we explicitly asks it do so (which we don't). There is also no need for a show_default=True parameter with the --caching option, since that option has _no_ default.
- Loading branch information
Showing
9 changed files
with
681 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.