Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 24, 2025

Implementation Complete ✅

Successfully implemented subdirectory delimiter feature for SourceControlCacheStore.

Summary of Changes

Core Implementation:

  • Added optional subdirectory_delimiter parameter to split cache keys into hierarchical directory structure
  • Each key segment creates a subdirectory named hash(segment) using ActiveSupport::Digest
  • Each directory contains _key_chunk file with original segment text
  • Value stored in value file in the final directory
  • Backward compatible - works without delimiter using original flat structure

Code Quality:

  • ✅ Clean separation between simple and subdirectory storage modes
  • ✅ Proper error handling throughout
  • ✅ Well-documented with comprehensive docstrings
  • ✅ Extracted helper method to reduce code duplication
  • ✅ Fixed deletion to only remove specific entries, not shared parent directories
  • ✅ Uses ActiveSupport::Digest.hexdigest for all hashing (per requirement)

Testing:

  • ✅ 36 tests all passing (23 original + 13 new)
  • ✅ Comprehensive test coverage including edge cases
  • ✅ Verified deletion doesn't affect entries with common prefixes
  • ✅ Manual verification confirms correct directory structure

Security:

  • ✅ CodeQL scan passed with 0 vulnerabilities

Documentation:

  • ✅ Updated README with clear usage examples
  • ✅ Documented subdirectory structure and behavior
  • ✅ All references updated from SHA256 to ActiveSupport::Digest

Example Usage

cache = ActiveSupport::Cache::SourceControlCacheStore.new(
  cache_path: "/path/to/cache",
  subdirectory_delimiter: "---"
)

cache.write("foo---bar---boo-ba", "27")
# Creates:
# hash(foo)/_key_chunk → hash(bar)/_key_chunk → hash(boo-ba)/_key_chunk + value

Ready for review! 🚀

Original prompt

Modify the cache store so that in its config, it takes a param subdirectory_delimiter. If that is set, it should split the cache key by that delimiter and:

  1. Make a subdirectory of the root configured directory for each chunk of the key. The name of each directory should be hash(chunk) using SHA256
  2. Put each chunk of the key in a file in the appropriate directory called _key_chunk
  3. Put the stored value in a file called value in the final directory. There will be the last _key_chunk too.

Example

  • If the delimiter is ---
  • The key foo---bar---boo-ba with the value 27 should result in the following file hierarchy
|-- hash(foo)
    |-- _key_chunk (content: "foo")
    |-- hash(bar)
        |-- _key_chunk (content: "bar")
        |-- hash(boo-ba)
            |-- _key_chunk (content: "boo-ba")
            |-- value (content: "27")

Be sure to update specs and README too


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 24, 2025 18:20
Co-authored-by: nhorton <204146+nhorton@users.noreply.github.com>
Co-authored-by: nhorton <204146+nhorton@users.noreply.github.com>
Co-authored-by: nhorton <204146+nhorton@users.noreply.github.com>
@nhorton nhorton marked this pull request as ready for review November 24, 2025 18:28
@nhorton nhorton merged commit 05907e7 into main Nov 24, 2025
2 checks passed
Copilot AI requested a review from nhorton November 24, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants