Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(cache): invalidate SCM caches when branch changes #6014

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

heaths
Copy link
Contributor

@heaths heaths commented Dec 14, 2024

Resolves #6012

@heaths
Copy link
Contributor Author

heaths commented Dec 14, 2024

This is only a WIP, but wanted to get any initial feedback. I realized as I was about to submit this that I don't think we can take a cache "tag" (with HTTP etags as an influence) only into account but will have to consider that along with a cache duration because info like the number of modified, removed, and added files, etc., is also part of that cache and would never update. Still, it's a start, if you're interested in the feature and have any initial feedback.

@heaths
Copy link
Contributor Author

heaths commented Dec 14, 2024

I updated the algorithm to always take duration into account. Testing with local edits, this works and makes much more sense. I set my duration to 10s and added/removed files. The prompt most often doesn't pick them up right away unless I switch branches or checkout HEAD~ as detached, etc.

If you're good with this, I can proceed with any feedback, add tests, and update other SCMs that could benefit. I'd have to research a few of them given either lack of familiarity or, like with mercurial, it's been a while since I've used and don't remember its housekeeping.

@heaths heaths changed the title feat(cache): cache SCM segments for current branch feat(cache): invalidate SCM caches when branch changes Dec 14, 2024
@heaths heaths marked this pull request as ready for review December 16, 2024 09:05
@heaths
Copy link
Contributor Author

heaths commented Dec 16, 2024

Tested against main and linked worktrees as well as submodules. Switching branches immediately refreshes info e.g., repo modifications. cd'ing into submodules and back retains the cache for the specified duration e.g., 30s.

@JanDeDobbeleer JanDeDobbeleer enabled auto-merge (rebase) December 17, 2024 19:47
@JanDeDobbeleer JanDeDobbeleer merged commit b869b3c into JanDeDobbeleer:main Dec 18, 2024
9 checks passed
@JanDeDobbeleer
Copy link
Owner

@all-contributors please add @heaths for code

This is pure magic 🪄! @holopin-bot @heaths wizard

Copy link

holopin-bot bot commented Dec 18, 2024

Congratulations @heaths, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/cm4tlltuc34590cjg2k9z90st

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply # with GitHub, which will do the trick!

Copy link
Contributor

@JanDeDobbeleer

I've put up a pull request to add @heaths! 🎉

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow some segment-related command to refresh segment cache
2 participants