Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable cache size limit #2536

Merged
merged 1 commit into from
Oct 23, 2018
Merged

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Oct 10, 2018

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, or null 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:

  1. Files that do not correspond to any download in the registry (mods that you downloaded before their URLs changed, such as old KerbalStuff files)
  2. Files that are in the registry but are not compatible with any of your game instances (mods that you downloaded when you were using old game versions)
  3. Files that are compatible with at least one of your game instances

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 unlimited
  • ckan 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 given

These 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:

image

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.

@HebaruSan HebaruSan added Enhancement New features or functionality GUI Issues affecting the interactive GUI Cmdline Issues affecting the command line Core (ckan.dll) Issues affecting the core part of CKAN Pull request Network Issues affecting internet connections of CKAN labels Oct 10, 2018
@politas
Copy link
Member

politas commented Oct 13, 2018

This is great, but can we add a manual "purge" button to bring the cache down to the limit set? If the UI is getting too cluttered, we could just replace the "Clear" button, and users could set the cache max size to 0 if they want to completely empty it.

@HebaruSan
Copy link
Member Author

Replaced the Clear button with a Purge dropdown menu button with both of those choices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmdline Issues affecting the command line Core (ckan.dll) Issues affecting the core part of CKAN Enhancement New features or functionality GUI Issues affecting the interactive GUI Network Issues affecting internet connections of CKAN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants