Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Task: Replace custom built cache in lockdown.go with cache2go ✅

Completed Changes

  • Add cache2go dependency to go.mod
  • Replace custom cache map with cache2go.CacheTable
  • Update GetRepoAccessInfo to use cache2go API (Add/Value methods)
  • Remove custom timer management code (scheduleExpiry, ensureEntry)
  • Update SetTTL to work with cache2go's existing items
  • Use unique cache names to avoid test interference
  • Ensure all existing tests pass
  • Verify builds and run tests
  • Run security checks (CodeQL)
  • Verify no vulnerabilities in new dependency

Summary

Successfully replaced the custom cache implementation in pkg/lockdown/lockdown.go with the cache2go library from https://github.com/muesli/cache2go.

What was removed:

  • Custom map[string]*repoAccessCacheEntry storage (18 lines removed)
  • Manual timer-based TTL expiration logic (scheduleExpiry method - 24 lines removed)
  • Per-entry timer field and management
  • Helper method ensureEntry (13 lines removed)

What was added:

  • cache2go.CacheTable for cache storage
  • Automatic TTL management via cache2go's built-in expiration
  • Unique cache names per instance to prevent test interference
  • Atomic counter for generating unique cache names

Key benefits:

  • ✅ Cleaner, more maintainable code (net reduction of ~4 lines)
  • ✅ Proven, well-tested cache library
  • ✅ Automatic expiration handling
  • ✅ Thread-safe by design
  • ✅ No behavioral changes

Testing:

  • All existing tests pass (run 5 times to verify stability)
  • No security vulnerabilities found (CodeQL clean)
  • No vulnerabilities in cache2go dependency (GitHub Advisory DB clean)
  • Full test suite passes

Security Summary

✅ No security vulnerabilities detected

  • CodeQL analysis: 0 alerts
  • Dependency check (github.com/muesli/cache2go): No known vulnerabilities
  • All security checks pass
Original prompt

Replace custom built cache in lockdown.go with a struct from this repository go https://github.com/muesli/cache2go

Created from VS Code via the GitHub Pull Request extension.


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

@JoannaaKL JoannaaKL marked this pull request as ready for review November 18, 2025 09:05
Copilot AI review requested due to automatic review settings November 18, 2025 09:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Added github.com/muesli/cache2go dependency
- Replaced custom map-based cache with cache2go.CacheTable
- Removed manual timer management (scheduleExpiry, ensureEntry methods)
- Removed timer field from repoAccessCacheEntry struct
- Updated GetRepoAccessInfo to use cache2go's Value() and Add() methods
- Updated SetTTL to flush and re-add entries with new TTL
- Used unique cache names per instance to avoid test interference
- All existing tests pass with the new implementation

Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
Copilot AI requested a review from a team as a code owner November 18, 2025 09:14
Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
@JoannaaKL JoannaaKL merged commit b27f1e2 into lockdown-mode-more-tools Nov 18, 2025
11 of 18 checks passed
@JoannaaKL JoannaaKL deleted the copilot/replace-custom-cache-implementation branch November 18, 2025 09:19
Copilot AI requested a review from JoannaaKL November 18, 2025 09:19
JoannaaKL added a commit that referenced this pull request Nov 21, 2025
* Apply lockdown mode to issues and pull requests

* Add cache

* Unlock in defer

* Add muesli/cache2go

* [WIP] Replace custom cache in lockdown.go with cache2go struct (#1425)

* Initial plan

* Replace custom cache with cache2go library

- Added github.com/muesli/cache2go dependency
- Replaced custom map-based cache with cache2go.CacheTable
- Removed manual timer management (scheduleExpiry, ensureEntry methods)
- Removed timer field from repoAccessCacheEntry struct
- Updated GetRepoAccessInfo to use cache2go's Value() and Add() methods
- Updated SetTTL to flush and re-add entries with new TTL
- Used unique cache names per instance to avoid test interference
- All existing tests pass with the new implementation

Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>

* Final verification complete

Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>

* Use muesli for cache

* Make RepoAccessCache a singleton (#1426)

* Initial plan

* Implement RepoAccessCache as a singleton pattern

Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>

* Complete singleton implementation and verification

Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>

* Remove cacheIDCounter as requested

Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>

* Update mutexes

* .

* Reuse cache

* .

* .

* Fix logic after vibe coding

* Update docs

* .

* Refactoring to make the code pretty

* Hide lockdown logic behind shouldFilter function

* .

* Tests

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
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