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.
Motivation
CKAN's download cache currently grows without limit. We write to it, but we don't remove files unless the user runs
ckan clean
or clicks the Clear button in the cache section of the GUI settings. This means that in order to avoid filling up a disk, the user might have to manually monitor the cache size and clear it periodically, or delete individual files. It would be nice to have something more automated.Changes
This pull request builds upon #2535 to create a configurable cache size limit. The default is to allow unlimited cache size, as it is today. (This pull request has been rebased to show only its own changes, where formerly #2535's commit was included.)
Core
Win32Registry.CacheSizeLimit
now stores the maximum number of bytes allowed in the cache, ornull
if unlimited.ModuleInstaller
enforces this limit after it finishes installing mods. Note that this means that we may temporarily exceed the limit during installation if required to fit the mods being installed. This also means that a user can set a limit of 0 bytes if they wish all downloads to be downloaded every time and never cached, and that will work.The algorithm to purge cache files will delete, in order:
Within each subgroup, files are deleted in age order, oldest first. Deletion stops once the total cache size falls under the limit. Both the main configurable cache folder and the legacy per-instance caches are checked and purged together according to the above rules, and we compare the sum of their sizes to the limit to determine compliance.
CmdLine
The
ckan cache
command has two new subcommands:ckan cache showlimit
- Print the cache size limit in MB, or "Unlimited" if unlimitedckan cache setlimit <new limit>
- Set the cache size limit to the argument in MB, or clear it to allow unlimited caching if no argument is givenThese commands do not enforce the limit. That will happen after mods are installed.
GUI
The cache section in the settings is expanded, the buttons are pushed down, and a limit field is added in the middle:
Changing this value does not immediately enforce the new limit (hence the size being over the limit in the above screenshot). That only happens after you install some mods. I don't want to auto-delete files while the user is still editing the value in the field, which may be smaller than their intended value.
The Clear button is replaced with a Purge dropdown button. When clicked, two options appear, one of which enforces the configured limit, the other of which deletes all files in the cache. If the cache is empty, the dropdown is disabled. If the cache is under the current limit, then the dropdown option to enforce the limit is disabled.
Fixes #2438.