Skip to content

feat: add purgeInMemoryCaches() to DederProjectInternals - #103

Merged
sake92 merged 2 commits into
mainfrom
feat/purge-inmemory-caches
Jun 18, 2026
Merged

feat: add purgeInMemoryCaches() to DederProjectInternals#103
sake92 merged 2 commits into
mainfrom
feat/purge-inmemory-caches

Conversation

@sake92

@sake92 sake92 commented Jun 18, 2026

Copy link
Copy Markdown
Owner
  • Add CacheStatsRegistry.invalidateAll() to flush all registered Scaffeine caches
  • Simplify CacheStatsRegistry.register() to accept SCache directly
  • Add PurgeCachesResult case class + purgeInMemoryCaches() to DederProjectInternals
  • Implement via callback pattern in DederProjectInternalsImpl
  • Add DederBspServer.cleanupCompletedInFlight() for stale BSP entries
  • Implement purge logic in DederProjectState with 10s idle wait, cache invalidation, history clearing, BSP cleanup, and GC suggestion
  • Wire callback in ServerMain
  • Add unit test for invalidateAll()

Summary by CodeRabbit

  • New Features

    • Added cache purging capability with detailed reporting on cleared caches, removed entries, and memory management suggestions.
    • Enhanced Zinc compiler with additional analysis caching to reduce disk I/O.
    • Improved memory management with coordinated in-flight request drainage before cache clearing.
  • Bug Fixes

    • Better cleanup of completed compilation entries to prevent memory leaks.

- Add CacheStatsRegistry.invalidateAll() to flush all registered Scaffeine caches
- Simplify CacheStatsRegistry.register() to accept SCache directly
- Add PurgeCachesResult case class + purgeInMemoryCaches() to DederProjectInternals
- Implement via callback pattern in DederProjectInternalsImpl
- Add DederBspServer.cleanupCompletedInFlight() for stale BSP entries
- Implement purge logic in DederProjectState with 10s idle wait, cache invalidation,
  history clearing, BSP cleanup, and GC suggestion
- Wire callback in ServerMain
- Add unit test for invalidateAll()
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ba17cd17-6190-4841-9282-68d00f6e173b

📥 Commits

Reviewing files that changed from the base of the PR and between 8e72096 and 9faa55d.

📒 Files selected for processing (11)
  • deder-common/src/ba/sake/deder/DederProjectInternals.scala
  • server/src/ba/sake/deder/CacheStatsRegistry.scala
  • server/src/ba/sake/deder/DederProjectInternalsImpl.scala
  • server/src/ba/sake/deder/DederProjectState.scala
  • server/src/ba/sake/deder/ServerMain.scala
  • server/src/ba/sake/deder/bsp/DederBspServer.scala
  • server/src/ba/sake/deder/deps/DependencyResolver.scala
  • server/src/ba/sake/deder/testing/inmemory/InMemoryTestOrchestrator.scala
  • server/src/ba/sake/deder/zinc/ZincCompiler.scala
  • server/src/ba/sake/deder/zinc/ZincCompilersCache.scala
  • server/test/src/ba/sake/deder/CacheStatsRegistrySuite.scala

📝 Walkthrough

Walkthrough

Adds a structured PurgeCachesResult return type to purgeInMemoryCaches(). Refactors CacheStatsRegistry to store live cache instances and adds invalidateAll(). Implements coordinated purge orchestration in DederProjectState that drains in-flight requests before invalidating caches, cleaning BSP entries, and clearing history. Wires the new function in ServerMain. Adds an analysisCache in ZincCompiler.

Changes

Cache Purge Implementation

Layer / File(s) Summary
PurgeCachesResult type and method contract
deder-common/src/ba/sake/deder/DederProjectInternals.scala
Adds PurgeCachesResult case class with cachesCleared, bspEntriesRemoved, historyEntriesRemoved, gcSuggested fields, and updates purgeInMemoryCaches() to return it.
CacheStatsRegistry refactor, callsite updates, and tests
server/src/ba/sake/deder/CacheStatsRegistry.scala, server/src/ba/sake/deder/deps/DependencyResolver.scala, server/src/ba/sake/deder/testing/inmemory/InMemoryTestOrchestrator.scala, server/src/ba/sake/deder/zinc/ZincCompiler.scala, server/src/ba/sake/deder/zinc/ZincCompilersCache.scala, server/test/src/ba/sake/deder/CacheStatsRegistrySuite.scala
CacheStatsRegistry switches from () => InMemCacheStats suppliers to storing SCache instances, adds invalidateAll(), and updates all registration callsites. ZincCompiler gains a new analysisCache. Tests are updated and a new invalidateAll test is added.
Purge orchestration, BSP cleanup, and server wiring
server/src/ba/sake/deder/DederProjectInternalsImpl.scala, server/src/ba/sake/deder/bsp/DederBspServer.scala, server/src/ba/sake/deder/DederProjectState.scala, server/src/ba/sake/deder/ServerMain.scala
Adds purgeCachesFn delegate and clearHistory() to DederProjectInternalsImpl, cleanupCompletedInFlight() to DederBspServer, and the full purgeInMemoryCachesImpl() orchestration in DederProjectState. ServerMain wires purgeCachesFn to the implementation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hop, hop, the caches grow stale,
But now we can purge without fail!
We wait for in-flight to land,
Then wipe with a capable hand—
GC suggested, results in paw,
The cleanest build you ever saw! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/purge-inmemory-caches

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sake92
sake92 merged commit cbb813a into main Jun 18, 2026
1 of 3 checks passed
@sake92
sake92 deleted the feat/purge-inmemory-caches branch June 18, 2026 18:18
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.

1 participant