Admin Guide: Cleaning up Riiif Cache Files

Purpose

ReSeeD uses Riiif to process and display images in the Universal Viewer (UV). To avoid downloading source files from S3 every time an image is requested, Riiif stores local copies of the source files in a cache directory.

The cache directory is located at:

/shared/cache/riiif_network_files/

This directory is shared between the ReSeeD web and worker containers.

Over time, cached source files can accumulate and consume disk space. ReSeeD provides a Rake task that allows administrators to remove old Riiif cache files.

When should the cleanup be performed?

Administrators are recommended to run the cleanup once or twice per month.

The default retention period is 7 days. Files whose modification time is older than seven days are eligible for deletion.

The cleanup also removes empty subdirectories left behind after file deletion.

Note: Only cached Riiif source files are affected. Original files stored in S3, generated derivatives, and other Hyrax cache files are not deleted.

Running the cleanup

The cleanup is implemented as a background job and can be triggered using a Rake task.

Run the following commands from the ReSeeD project directory on the server.

1. Preview files before deletion (dry run)

It is recommended to perform a dry run before deleting files:

docker exec rdms-web-1 \
  bash -lc 'DAYS=7 bundle exec rake riiif:cleanup_cache'

This queues the cleanup job through Sidekiq but does not delete any files. The job logs the files that would be deleted.

2. Delete old cache files

After reviewing the dry-run results, run:

docker exec rdms-web-1 \
  bash -lc 'DAYS=7 DELETE=1 bundle exec rake riiif:cleanup_cache'

This queues the cleanup job with deletion enabled. The Sidekiq worker processes the job and deletes eligible files and empty subdirectories.

The cleanup runs asynchronously, so the Rake command only queues the job. Administrators can check the worker logs to follow its execution. Look for messages indicating which files have been deleted and whether the cleanup has finished successfully.

3. Changing the retention period

The retention period can be configured using the DAYS environment variable.

For example, to delete cache files older than 14 days:

docker exec rdms-web-1 \
  bash -lc 'DAYS=14 DELETE=1 bundle exec rake riiif:cleanup_cache'

If DAYS is omitted, the default retention period is seven days.

Important notes

* The cleanup only affects files inside /shared/cache/riiif_network_files/.
* Files are selected based on their modification time (mtime), not their last access time.
* This means that a recently viewed image may still be deleted if its cache file has not been modified within the retention period.
* Deleted cache files can be downloaded again from S3 when the image is requested in the Universal Viewer.
* The cleanup requires a running Sidekiq worker to execute the background job.
* Always perform a dry run before enabling deletion, especially when using a different retention period.

ReSeeD administrators should perform the following steps once or twice per month:

1. Run the cleanup in dry-run mode.
2. Check the Sidekiq logs to review the files selected for deletion.
3. Run the cleanup with DELETE=1.
4. Check the worker logs to confirm that the job completed successfully.