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

Add rake task to clean cache #1634

Merged
merged 8 commits into from
Jan 16, 2023
Merged

Add rake task to clean cache #1634

merged 8 commits into from
Jan 16, 2023

Conversation

damianhxy
Copy link
Member

@damianhxy damianhxy commented Oct 28, 2022

Description

  • Expire cache contents after 7 days (with race_condition_ttl set to 1 minute -- used to avoid race conditions)
  • Add a rake task to facilitate cleaning the cache
  • Update troubleshooting portion of documentation

Motivation and Context

On 27 Oct, Autolab started returning 500 internal server errors due to the cache disk running out of inodes when attempting to write to the raw score caches. (autolab-error.pdf)

This is because FileStore caches (the default cache) are not purged automatically.

Reference: https://stackoverflow.com/questions/27502082/clearing-expired-cache-entries-from-disk-cache-on-ruby-on-rails-4

Unfortunately, there does not appear to be an easy way to periodically clear expired entries. In lieu of that, this PR adds a rake task and updates the documentation to facilitate the process

How Has This Been Tested?

Preliminary steps

  • Enable caching in development by running rails dev:cache
  • In development.rb, replace config.cache_store = :memory_store with config.cache_store = :file_store, "tmp/cache/scores"

Test that rake task clears expired entries

  • For testing purposes, change :expires_in and race_condition_ttl to 5.seconds (in all 3 places)
  • Load the gradesheet of an assessment (e.g. AutoPopulated / Homework0), observe that the path <AUTOLAB DIR>/tmp/cache/scores is populated
  • Wait a few seconds, run rake user:cleanup_cache, observe that the (expired) entries are cleared

Test that rake task does not clear unexpired entries

  • Change :expires_in and race_condition_ttl back to their original values
  • Load the gradesheet of an assessment (e.g. AutoPopulated / Homework0), observe that the path <AUTOLAB DIR>/tmp/cache/scores is populated
  • Wait a few seconds, run rake user:cleanup_cache, observe that the unexpired entries are not cleared
  • As a sanity check, run rake user:clear_cache and observe that the entries are cleared

Documentation

  • Run docs locally (mkdocs serve) and navigate to http://127.0.0.1:8000/installation/troubleshoot/#no-space-left-on-device-error

Screenshot 2022-12-30 at 09 39 42

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have run rubocop for style check. If you haven't, run overcommit --install && overcommit --sign to use pre-commit hook for linting
  • My change requires a change to the documentation, which is located at Autolab Docs
  • I have updated the documentation accordingly, included in this PR

@damianhxy damianhxy changed the title Add expiry for Rails.cache writes Set expiration for cache contents Dec 3, 2022
@damianhxy damianhxy marked this pull request as ready for review December 30, 2022 09:34
@damianhxy damianhxy requested a review from 20wildmanj December 30, 2022 09:34
@damianhxy damianhxy changed the title Set expiration for cache contents Add rake task to clean cache Dec 30, 2022
Copy link
Contributor

@20wildmanj 20wildmanj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that cache cleanup task successfully works for filestore cache, and expiration time works, and checked docs. LGTM

@damianhxy damianhxy merged commit 2ec8792 into master Jan 16, 2023
@damianhxy damianhxy deleted the expire-cache branch January 16, 2023 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants