{"id":16116639,"url":"https://github.com/dpc/fs-dir-cache","last_synced_at":"2025-11-10T16:05:46.940Z","repository":{"id":190734943,"uuid":"683199100","full_name":"dpc/fs-dir-cache","owner":"dpc","description":"A CLI tool for CIs and build scripts, making file system based caching easy and correct (locking, eviction, etc.)","archived":false,"fork":false,"pushed_at":"2025-06-05T21:05:00.000Z","size":88,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-07T12:01:57.472Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-25T20:49:58.000Z","updated_at":"2025-08-26T17:19:48.000Z","dependencies_parsed_at":"2023-08-26T05:37:39.728Z","dependency_job_id":"28b16da7-fe4f-4f6c-99c7-d5d222b1ab10","html_url":"https://github.com/dpc/fs-dir-cache","commit_stats":null,"previous_names":["dpc/fs-dir-cache"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dpc/fs-dir-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpc%2Ffs-dir-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpc%2Ffs-dir-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpc%2Ffs-dir-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpc%2Ffs-dir-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpc","download_url":"https://codeload.github.com/dpc/fs-dir-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpc%2Ffs-dir-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283707471,"owners_count":26880763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-10T02:00:06.292Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T20:25:06.014Z","updated_at":"2025-11-10T16:05:46.924Z","avatar_url":"https://github.com/dpc.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FS Dir Cache\n\nA CLI tool for CIs and build scripts, making file system based\ncaching easy and correct (locking, eviction, etc.)\n\nWhen working on build systems / CIs it's often a requirement to\nutilize some best effort caching, with locking and eviction.\n\nNot exactly rocket science, but non-trivial enough to not want\nto implement and maintain ad-hoc.\n\n`fs-dir-cache` aims to be a simple to use utility from inside\nother scripts and programs taking care of the details.\n\n## Example\n\nThis is an example, where a CI runner can persist files between runs,\nand it's used to to reuse build artifacts between builds that are likely\nbuilding the same build to speed everything up:\n\n\n```bash\n#!/usr/bin/env bash\n\nset -euo pipefail\n\njob_name=\"$1\"\nshift 1\n\nif [ -z \"$job_name\" ]; then\n    \u003e\u00262 \"error: no job name\"\n    exit 1\nfi\n\nexport FS_DIR_CACHE_LOCK_TIMEOUT_SECS=\"$((60 * 30))\" # unlock after timeout in case our job fails misereably and/or hangs\n\nexport FS_DIR_CACHE_ROOT=\"$HOME/.cache/fs-dir-cache\" # directory to hold all cache (sub)directories\nexport FS_DIR_CACHE_LOCK_ID=\"pid-$$-rnd-$RANDOM\"     # acquire lock based on the current pid and something random (just in case pid gets reused)\nexport FS_DIR_CACHE_KEY_NAME=\"$job_name\"             # the base name of our key\n\nlog_file=\"$FS_DIR_CACHE_ROOT/log\"\n\nfs-dir-cache gc unused --seconds \"$((5 * 24 * 60 * 60))\" # delete caches not used in more than a 5 days\n\nexport log_file # log when each job starte and ended\nexport job_name\nsrc_dir=$(pwd)\nexport src_dir\n\n# This bash command will be executed with a CWD set to the allocated directory\nfunction run_in_cache() {\n    echo \"$(date --rfc-3339=seconds) RUN job=$job_name dir=$(pwd)\" \u003e\u003e \"$log_file\"\n    \u003e\u00262 echo \"$(date --rfc-3339=seconds) RUN job=$job_name dir=$(pwd)\"\n    CARGO_BUILD_TARGET_DIR=\"$(pwd)\"\n    export CARGO_BUILD_TARGET_DIR\n    cd \"$src_dir\"\n\n    function on_exit() {\n        local exit_code=$?\n\n        echo \"$(date --rfc-3339=seconds) END job=$job_name code=$exit_code\" \u003e\u003e \"$log_file\"\n        \u003e\u00262 echo \"$(date --rfc-3339=seconds) END job=$job_name code=$exit_code\"\n\n        exit $exit_code\n    }\n    trap on_exit EXIT\n\n    \"$@\"\n}\nexport -f run_in_cache\n\n\nfs-dir-cache exec \\\n    --key-file Cargo.lock\n    --key-str \"${CARGO_PROFILE-:dev}\" \\\n    --key-file flake.lock \\\n    -- \\\n    bash -c 'run_in_cache \"$@\"' _ \"$@\"\n```\n\nUsing just one tool, it's easy to get correct and practical caching including:\n\n* locking (including fallback timeouts)\n* evicition\n* timeouts\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpc%2Ffs-dir-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpc%2Ffs-dir-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpc%2Ffs-dir-cache/lists"}